Ver Mensaje Individual
  #3 (permalink)  
Antiguo 10/02/2013, 09:45
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 9 meses
Puntos: 1567
Respuesta: Imprimi archivo externo

Cita:
Iniciado por fharid Ver Mensaje
Buenos dias , mi duda es sobre algo que estoy desarrollando
imprimo un archivo .txt en un ticketera con formato generic text only
por lo tanto no hay problema de hecho funciona bien en .txt

el caso es que me funciona sin problemas en internet explorer


<head>
<link rel="alternate" media="print" href="archivo.txt"/>
<script>
function printArc(){
javascript:window.print()

}
</script>
<title>IMPRESION DE TICKET</title>
</head>




<body>
<input type="button" value="I M P R I M I R" onclick="printArc()" style='width:150px; height:100px'/>



he estado informandomen y solo funciona en IE , pero quisiera que me compartan otra opcion para jalar este archivo que se encuentra en el servidor y cuando le de click a algo me arroje seleccionar la impresora e imprima ese archivo y no la pagina que despliega


Saludos
Si, lamentablemente no es muy compatible.

Podrías hacer algo asi

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <html lang="es-ar">
  3. <meta charset="utf-8" />
  4. <title>xxxxx</title>
  5.  
  6. <style type="text/css">
  7. /*<![CDATA[*/
  8.  
  9. /* esto afecta a la vista del navegador en pantalla */
  10. @media screen {
  11.    
  12.     .contenido_pantalla{
  13.     width: 300px;
  14.     margin: 100px auto;
  15.     text-align: center;
  16.     }
  17.     .contenido_impresion{
  18.     display: none;
  19.     }
  20.  
  21. }
  22. /* esto a la vista impresion, oculta los elementos menos el area que contiene el ticket */
  23. @media print{
  24.    
  25.     .espere{
  26.     display: none;
  27.     }
  28.     .contenido_impresion{
  29.     display: block;
  30.     }
  31.  
  32. }
  33.  
  34. /*]]>*/
  35. </head>
  36. <div class='contenido_pantalla'>contenido visible en pantalla</div>
  37. <div class='contenido_impresion'><pre>Ticket 001
  38. á é í Ñ ñ</pre></div></body>
  39. </html>


Claro que en ese caos deberías ver de incluir el código del ticket en el html

Esto otro, requiere de php, es un poco más complejo pero mucho más manejable

imprime_ticket.html

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <html lang="es-ar">
  3. <meta charset="utf-8" />
  4. <title>IMPRESION DE TICKET</title>
  5.  
  6. <style type="text/css">
  7. /*<![CDATA[*/
  8.  
  9. .botones{
  10. width: 150px; padding: 50px; background: buttonface; display: block;text-decoration: none; text-align: center;border: outset 1px buttonface;
  11. }
  12. .botones:hover{
  13. border: inset 1px buttonface;
  14. }
  15.  
  16. /*]]>*/
  17. <script type="text/javascript">
  18. //<![CDATA[
  19. var nvcarga= null;
  20. function ventana_imprime(pagina,w,h,nombre){
  21. var winleft = (screen.width-w)/2;
  22. var wintop = (screen.height-h)/2;
  23. caracteristicas='height='+h+',width='+w+',top='+wintop+',left='+winleft+',titlebar=no,scrollbars=yes,location=0,toolbar=0,resizable=yes'
  24. nvcarga=window.open(pagina,nombre,caracteristicas);
  25. if(parseInt(navigator.appVersion) >= 4){nvcarga.window.focus();}
  26. }
  27. //]]>
  28.  
  29. </head>
  30. <div>
  31. <a href="imprime.php?archivo=ticket_001" class="botones" onclick="ventana_imprime('imprime.php?archivo=ticket_001',400,400,'vimp'); return false;">IMPRIMIR ticket 001</a><br />
  32. <a href="imprime.php?archivo=ticket_002" class="botones" onclick="ventana_imprime('imprime.php?archivo=ticket_002',400,400,'vimp'); return false;">IMPRIMIR ticket 002</a>
  33. </div>
  34. <iframe src="about:blank" name="area_impresion" id="area_impresion"
  35. style='width:0px; height:0px; border: none; display: none;'></iframe>
  36. </body>
  37. </html>

Como ves cada botón abre una nueva ventana y entre los parámetros se pasa el nombre del ticket, luego imprime.php
Código PHP:
Ver original
  1. <?php $archivo = $_GET['archivo']; ?>
  2. <!DOCTYPE html>
  3. <html lang="es-ar">
  4. <head>
  5. <meta charset="utf-8" />
  6. <title>Imprimiendo <?php echo $archivo ; ?></title>
  7.  
  8. <style type="text/css">
  9. /*<![CDATA[*/
  10. @media screen {
  11.    
  12.     .espere{
  13.     width: 300px;
  14.     margin: 100px auto;
  15.     text-align: center;
  16.     }
  17.     .contenido_impresion{
  18.     display: none;
  19.     }
  20.  
  21. }
  22. @media print{
  23.    
  24.     .espere{
  25.     display: none;
  26.     }
  27.     .contenido_impresion{
  28.     display: block;
  29.     }
  30.  
  31. }
  32.  
  33. /*]]>*/
  34. </style>
  35. <script type="text/javascript">
  36. //<![CDATA[
  37. window.onload= function imprime(){
  38. window.print();
  39. setTimeout('window.close()', 1200);
  40. }
  41. //]]>
  42. </script>
  43. </head>
  44. <body>
  45. <?php
  46. echo "<div class='espere'>Imprimiendo <b>$archivo</b></div>";
  47. echo "<div class='contenido_impresion'><pre>" . file_get_contents($archivo . '.txt') . "</pre></div>";
  48. ?>
  49. </body>
  50. </html>

En el css usamos la primer técnica, incluimos el contenido del ticket agregando la extensión .txt, y onload hacés el window.print y autocerrás la ventana. Testeado en Chrome, FF, IE, Safari, y en opera imprime correctamente pero no cierra la ventana.

Como ves con este ultimo sistema podés imprimir diferentes archivos desde difeentes botones en el imprimir_ticket.html


Aclaración, la extensión printer de php está solo disponible para windows, y en todo caso trabaja con impresoras vinculadas al server no al cliente

SAludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.