elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  Imprimir desde Java
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Imprimir desde Java  (Leído 1,918 veces)
mapers


Desconectado Desconectado

Mensajes: 638


Ver Perfil
Imprimir desde Java
« en: 12 Febrero 2015, 05:28 am »

Buenas señores del foro necesito de su sabiduria; tengo una impresora epson tm h6000 qquisiera saber como poder mandar para que imprima los tickets.Si tuvieran un ejemplo de donde guiarme se lo agradeceria .


En línea

Usuario Invitado


Desconectado Desconectado

Mensajes: 625



Ver Perfil
Re: Imprimir desde Java
« Respuesta #1 en: 12 Febrero 2015, 06:10 am »

Ejemplo:

Código
  1. import java.io.*;
  2. import javax.print.*;
  3.  
  4. public class PrintTest {
  5. public static void main(String[] args) throws IOException {
  6.  //we are going to print "printtest.txt" file which is inside working directory
  7.  File file = new File("printtest.txt");
  8.  
  9.  //Discover the default print service. If you call PrintServiceLookup.lookupPrintServices
  10.  //then it will return an array of print services available and you can choose a
  11.  //printer from them
  12.  PrintService service = PrintServiceLookup.lookupDefaultPrintService();
  13.  
  14.  //Doc flavor specifies the output format of the file (Mime type + Char encoding)
  15.  //You can retrieve doc flavors supported by the printer, like this
  16.  //DocFlavor [] supportedFlavors = service.getSupportedDocFlavors();
  17.  DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;  
  18.  
  19.  
  20.  // Create the print job
  21.  DocPrintJob job = service.createPrintJob();
  22.  //Create the Doc. You can pass set of attributes(type of PrintRequestAttributeSet) as the
  23.  //3rd parameter specifying the page setup, orientation, no. of copies, etc instead of null.
  24.  Doc doc = new SimpleDoc(is, flavor, null);
  25.  
  26.  //Order to print, (can pass attributes instead of null)
  27.  try {
  28.   job.print(doc, null);
  29.  } catch (PrintException e) {
  30.   e.printStackTrace();
  31.  }  
  32.  
  33.  //DocPrintJob.print() is not guaranteed to be synchronous. So it's better to wait on completion
  34.  //of the print job before closing the stream. (See the link below)
  35.  is.close();
  36.  System.out.println("Printing done....");
  37. }
  38.  
  39. }

Leer más: http://kalanir.blogspot.com/2010/10/how-to-print-from-java-jps-javaxprint.html


En línea

"La vida es muy peligrosa. No por las personas que hacen el mal, si no por las que se sientan a ver lo que pasa." Albert Einstein
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Imprimir en Java????
Java
cimi 7 12,530 Último mensaje 5 Diciembre 2005, 03:56 am
por DarkSatriani
[BATCH] Imprimir variables desde un .txt
Scripting
Dany3j 4 5,335 Último mensaje 4 Abril 2012, 22:32 pm
por Dany3j
Imprimir desde php
PHP
josco 3 6,309 Último mensaje 12 Julio 2012, 09:26 am
por adastra
imprimir pdf desde link
Desarrollo Web
basickdagger 1 2,068 Último mensaje 11 Marzo 2014, 20:06 pm
por #!drvy
incompatibilidad al imprimir en matriciales epson lx350 desde java
Java
christianvmc 2 3,928 Último mensaje 10 Abril 2020, 06:19 am
por rub'n
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines