/** * Prints the document at its actual size. This is the recommended way to print. */ private static void print(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); job.print(); }
@Override public Printable getPrintable(int i) { if (i >= getNumberOfPages()) { throw new IndexOutOfBoundsException(i + " >= " + getNumberOfPages()); } PDFPrintable printable = new PDFPrintable(document, Scaling.ACTUAL_SIZE, showPageBorder, dpi); printable.setSubsamplingAllowed(subsamplingAllowed); printable.setRenderingHints(renderingHints); return printable; } }
PDFPageable pageable = new PDFPageable(document, orientation, showPageBorder, dpi); pageable.setRenderingHints(renderingHints); printJob.setPageable(pageable);
public boolean check() throws Exception { try (PDDocument document = PDDocument.load(in)) { PDDocumentCatalog catalog = document.getDocumentCatalog(); PDFPageable pageable = new PDFPageable(document); PageFormat firstPage = pageable.getPageFormat(0);
/** * Prints with a print preview dialog. */ private static void printWithDialog(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); if (job.printDialog()) { job.print(); } }
@Override public Printable getPrintable(int i) { if (i >= getNumberOfPages()) { throw new IndexOutOfBoundsException(i + " >= " + getNumberOfPages()); } return new PDFPrintable(document, Scaling.ACTUAL_SIZE, showPageBorder, dpi); } }
/** * Prints using custom PrintRequestAttribute values. */ 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); }
@Override public Printable getPrintable(int i) { if (i >= getNumberOfPages()) { throw new IndexOutOfBoundsException(i + " >= " + getNumberOfPages()); } return new PDFPrintable(document, Scaling.ACTUAL_SIZE, showPageBorder, dpi); } }
job.setPageable(new PDFPageable(document)); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); PDViewerPreferences vp = document.getDocumentCatalog().getViewerPreferences();
job.setPageable(new PDFPageable(document));
/** * Prints using a custom page size and custom margins. */ 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(); } }
/** * Prints the document at its actual size. This is the recommended way to print. */ private static void print(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); job.print(); }
/** * Prints with a print preview dialog. */ private static void printWithDialog(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); if (job.printDialog()) { job.print(); } }
/** * Prints using custom PrintRequestAttribute values. */ 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); }
printJob.setPageable(new PDFPageable(document, orientation, showPageBorder, dpi));
job.setPageable(new PDFPageable(document));
/** * Prints using a custom page size and custom margins. */ 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(); } }