Tema: Imprimir PDF
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/08/2015, 11:01
RadicalEd
 
Fecha de Ingreso: octubre-2004
Ubicación: COLOMBIA
Mensajes: 240
Antigüedad: 19 años, 6 meses
Puntos: 3
Imprimir PDF

Hola chicos, tengo una duda, estoy implementando una impresión de un PDF, lo hago con éste código
Código Java:
Ver original
  1. public String imprimir(String turno, String servicio, Date fecha)
  2.                            throws FileNotFoundException, DocumentException, IOException {
  3.         // Se crea el documento
  4.         Rectangle pagesize = new Rectangle(200f, 275f);
  5.         Document documento = new Document(pagesize, 5, 5, 5, 5);
  6.         documento.addTitle("Turnos Onvacation");
  7.         documento.addSubject("Generado desde Software Turnero");
  8.  
  9.         // Se crea el OutputStream para el fichero donde queremos dejar el pdf.
  10.         FileOutputStream ficheroPdf = new FileOutputStream("fichero.pdf");
  11.  
  12.         // Se asocia el documento al OutputStream y se indica que el espaciado entre
  13.         // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
  14.         PdfWriter.getInstance(documento,ficheroPdf).setInitialLeading(1);
  15.  
  16.         // Se abre el documento.
  17.         documento.open();
  18.        
  19.         documento.add(new Paragraph("           ON VACATION\n" +
  20.                                     "           Con todo incluido y a tu alcance",
  21.                         FontFactory.getFont("arial",   // fuente
  22.                         10)));          
  23.         try {
  24.             com.itextpdf.text.Image foto = com.itextpdf.text.Image.getInstance("logo_small.png");
  25.             foto.setAlignment(Chunk.ALIGN_LEFT);
  26.             documento.add(foto);
  27.         } catch (Exception e) {
  28.             e.printStackTrace();
  29.         }                
  30.         documento.add(new Paragraph("SERVICIO:\n        "+servicio,
  31.                         FontFactory.getFont("arial",   // fuente
  32.                         10)));
  33.        
  34.         Paragraph elturno = new Paragraph("TURNO",
  35.                           FontFactory.getFont("arial",   // fuente
  36.                           15));
  37.         elturno.setAlignment(Chunk.ALIGN_CENTER);
  38.         documento.add(elturno);          
  39.         Paragraph turnoStr = new Paragraph(turno,
  40.                           FontFactory.getFont("arial",   // fuente
  41.                           30));
  42.         turnoStr.setAlignment(Chunk.ALIGN_CENTER);
  43.         documento.add(turnoStr);
  44.         Paragraph lafecha = new Paragraph(""+fecha,
  45.                             FontFactory.getFont("arial",   // fuente
  46.                             10));
  47.         lafecha.setAlignment(Chunk.ALIGN_CENTER);
  48.         documento.add(lafecha);          
  49.        
  50.         documento.close();
  51.        
  52.         FileInputStream inputStream = null;
  53.         try {
  54.             inputStream = new FileInputStream("./fichero.pdf");
  55.         } catch (FileNotFoundException e) {
  56.             e.printStackTrace();
  57.         }
  58.         if (inputStream == null) {
  59.             return "1";
  60.         }
  61.         DocFlavor docFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
  62.         Doc document = new SimpleDoc(inputStream, docFormat, null);
  63.  
  64.         PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
  65.         PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
  66.  
  67.  
  68.         if (defaultPrintService != null) {
  69.             DocPrintJob printJob = defaultPrintService.createPrintJob();
  70.             try {
  71.                 printJob.print(document, attributeSet);
  72.  
  73.             } catch (Exception e) {
  74.                 e.printStackTrace();
  75.             }
  76.         } else {
  77.             System.err.println("No existen impresoras instaladas");
  78.         }
  79.  
  80.         inputStream.close();
  81.         return "ok";
  82.     }
Corre perfectamente en Linux y me imprime éste recibo

Al intentar imprimirlo en Windows me aparece el pdf en plano, ósea, ésto
Código:
%PDF-1.4
%����1 0 obj
<</ColorSpace/DeviceGray/Subtype/Image/Height 25/Filter/FlateDecode/Type/XObject/Width 65/Length 892/BitsPerComponent 8>>stream
x��T^MHUg^X~<���j&f     �˲ٚ�4+^?���^U�4+B��Eݚ՚4^VښҚ0�(Ś^R)b�V�ǚ&kX��b6^ÚZn^Y1^W��՚^\���S�^E�ݿg�9 {5�^F�^^8�{ �}��� �}^_�YnCk�ů˯�09�"-&��6>گ<     �o?m&:�i�D�ʯ#�ͯF�۴2aɴ'^CB$
/��ث[M�,�
Me podrían explicar qué se debe agregar para que funcione en Windows.

Gracias
__________________
Revista Código Latino
SoloCodigo