List of usage examples for org.apache.pdfbox.printing PDFPageable PDFPageable
public PDFPageable(PDDocument document)
From source file:FileIOAux.PrintAux.java
public synchronized void print() { int val = this.showDialog(dialogo); if (val > -1) { try {//from w w w .j av a 2 s.c o m try (PDDocument pdf = PDDocument.load(file)) { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(pdf)); job.setPrintService(impressoras[val]); switch (valorqualidade) { case 5: parametros.add(PrintQuality.HIGH); break; case 3: parametros.add(PrintQuality.DRAFT); break; default: parametros.add(PrintQuality.NORMAL); break; } switch (valorlados) { case 1: parametros.add(Sides.DUPLEX); break; case 2: parametros.add(Sides.TUMBLE); break; default: parametros.add(Sides.ONE_SIDED); break; } switch (valorcores) { case 0: parametros.add(Chromaticity.MONOCHROME); break; default: parametros.add(Chromaticity.COLOR); break; } parametros.add(new PageRanges(valorminimo, valormaximo)); parametros.add(new Copies(ncopias)); job.print(parametros); } } catch (FileNotFoundException ex) { Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException | PrinterException ex) { Logger.getLogger(PrintAux.class.getName()).log(Level.SEVERE, null, ex); } } try { doc.close(); } catch (IOException ex) { Logger.getLogger(PrintAux.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.nmrfx.processor.gui.spectra.SpectrumWriter.java
License:Open Source License
public static void printGraphics(GraphicsIO gIO) { if (gIO instanceof PDFWriter) { PDFWriter writer = (PDFWriter) gIO; PDPageContentStream contentStream = writer.getContentStream(); PDDocument doc = writer.getDocument(); try {/*w w w. j av a 2 s . c om*/ contentStream.close(); } catch (IOException ioE) { System.out.println(ioE.getMessage()); return; } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final PrinterJob job = PrinterJob.getPrinterJob(); if (job.printDialog()) { job.setPageable(new PDFPageable(doc)); try { job.print(); } catch (PrinterException pE) { System.out.println(pE.getMessage()); } } } }); } }
From source file:printInv.GenerateInvoice.java
public static void invoice() throws PrinterException { System.out.println("indexs ====" + n); String pdfFilename = "Invoice.pdf"; GenerateInvoice generateInvoice = new GenerateInvoice(); generateInvoice.createPDF(pdfFilename); PrinterJob job = PrinterJob.getPrinterJob(); try {//from ww w. jav a 2s. c o m PDDocument doc = PDDocument.load(new File("Invoice.pdf")); job.setPageable(new PDFPageable(doc)); if (job.printDialog()) { job.print(); } } catch (Exception ex) { Logger.getLogger(GenerateInvoice.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:qrscanner.QRScanner.java
public static void printPDF() throws Exception { //printPDF("ZJ-58",pdfPath); Path currentRelativePath = Paths.get(""); String pdfPath = currentRelativePath.toAbsolutePath().toString() + "\\QRscannedpdf.pdf"; System.out.println("Current relative path is: " + pdfPath); PDDocument document = PDDocument.load(new File(pdfPath)); PrintService myPrintService = findPrintService("ZJ-58"); PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); job.setPrintService(myPrintService); job.print();// w w w. j a va2 s.c om }