use of org.apache.pdfbox.printing.PDFPrintable in project pdfbox by apache.
the class Printing method printWithPaper.
/**
* 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();
// 1/72 inch
paper.setSize(306, 396);
// no margins
paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight());
// 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();
}
Aggregations