List of usage examples for org.apache.pdfbox.printing PDFPageable PDFPageable
public PDFPageable(PDDocument document)
From source file:FormFiller.java
private static void printPdf(PDDocument pdfTemplate, HashMap dealerTrackData, String inputFileName, int copies) { try {/* www .j a v a 2 s. co m*/ PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(pdfTemplate)); // Print out of oversize tray for oversize contract - beta - not sure if this works! if (!dealerTrackData.get("buyerState").equals("CA") && inputFileName.contains("Purchase Contract")) { PrintRequestAttributeSet pset = new HashPrintRequestAttributeSet(); pset.add(Sides.DUPLEX); Media[] supportedMedia = (Media[]) job.getPrintService().getSupportedAttributeValues(Media.class, null, null); for (Media m : supportedMedia) { if (m.toString().equals("Tray 5")) { pset.add(m); break; } } for (int i = 0; i < copies; i++) job.print(pset); return; } for (int i = 0; i < copies; i++) job.print(); } catch (PrinterException e) { e.printStackTrace(); } }
From source file:adams.core.io.PDFBox.java
License:Open Source License
/** * Prints the PDF document./*from ww w . j a v a 2s. c om*/ * * @param document the PDF document to print * @return true if successfully printed */ public static boolean print(PDDocument document) { try { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); job.print(); return true; } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to print PDF document!", e); return false; } }
From source file:adams.core.io.PDFBox.java
License:Open Source License
/** * Prints the PDF document, bringing up a dialog. * * @param document the PDF document to print * @return true if successfully printed *///from w w w .j a v a 2 s.co m public static boolean printWithDialog(PDDocument document) { try { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); if (job.printDialog()) { job.print(); return true; } else { return false; } } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to print PDF document!", e); return false; } }
From source file:com.coast.PDFPrinter.java
License:Apache License
/** * Prints the document at its actual size. This is the recommended way to print. *///from w ww. j a va 2s. co m private static void print(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); job.print(); }
From source file:com.coast.PDFPrinter.java
License:Apache License
/** * Prints using custom PrintRequestAttribute values. *//*from ww w. j a v a 2 s .c om*/ private static void printWithAttributes(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(new PageRanges(1, 1)); // pages 1 to 1 job.print(attr); }
From source file:com.coast.PDFPrinter.java
License:Apache License
/** * Prints with a print preview dialog.//from w w w . j a va 2 s . co m */ private static void printWithDialog(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); if (job.printDialog()) { job.print(); } }
From source file:com.coast.PDFPrinter.java
License:Apache License
/** * Prints with a print preview dialog and custom PrintRequestAttribute values. */// w w w . j a v a2s . co m private static void printWithDialogAndAttributes(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(new PageRanges(1, 1)); // pages 1 to 1 if (job.printDialog(attr)) { job.print(attr); } }
From source file:com.coast.PDFPrinter.java
License:Apache License
/** * Prints using a custom page size and custom margins. *///from www . j a v a 2s .c o m private static void printWithPaper(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); // define custom paper Paper paper = new Paper(); paper.setSize(306, 396); // 1/72 inch paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight()); // no margins // custom page format PageFormat pageFormat = new PageFormat(); pageFormat.setPaper(paper); // override the page format Book book = new Book(); // append all pages book.append(new PDFPrintable(document), pageFormat, document.getNumberOfPages()); job.setPageable(book); job.print(); }
From source file:com.ecm.pdfbox.PdfPrinting.java
License:Apache License
/** * Prints the document at its actual size. This is the recommended way to print. */// ww w . j a va2s . co m private static void print(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); job.print(); }
From source file:Control.MyiReportVisor.java
/** * si se desea imprimir solo una hoja, se llama al objeto "printr" * si se desea imprimir hoja + copia, se llama al objeto "pages" *///from w ww. j a va2 s .c o m public void exportarAPdfConCopia() throws IOException { try { //EXPORTANDO PDF System.out.println("Exportando a pdf"); final JRPdfExporter exp = new JRPdfExporter(); exp.setParameter(JRExporterParameter.JASPER_PRINT_LIST, pages); exp.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); exp.setParameter(JRExporterParameter.OUTPUT_FILE, new File("D:\\pdfGenerados\\" + nombreArchivo + ".pdf")); exp.exportReport(); PrinterJob job = PrinterJob.getPrinterJob(); PDDocument pdc = PDDocument.load(new File("D:\\pdfGenerados\\" + nombreArchivo + ".pdf")); System.out.println("" + pdc.getNumberOfPages()); job.setPageable(new PDFPageable(pdc)); try { job.print(); } catch (PrinterException ex) { Logger.getLogger(MyiReportVisor.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Mostrando PDF"); //Abriendo PDF //Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler "+"D:\\pdfGenerados\\" + nombreArchivo + ".pdf"); } catch (JRException ex) { ex.printStackTrace(); } }