if (jobName == null) {
jobName = "";
}
try {
final ByteBuffer bb = ByteBuffer.wrap(pdf.getByteArray());
final PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page
final PDFPrintPage printPages = new PDFPrintPage(pdfFile); // Create
// Print
// Job
final PrinterJob pjob = PrinterJob.getPrinterJob();
final PageFormat pf = PrinterJob.getPrinterJob().defaultPage();
// Format for DIN A4 page size
final Paper paper = new Paper();
paper.setSize(595.275591, 841.889764); // width, height of DIN-A4 at
// 72dpi
paper.setImageableArea(0, 0, paper.getWidth() * 2,
paper.getHeight());
pf.setPaper(paper);
pjob.setJobName(jobName);
final Book book = new Book();
book.append(printPages, pf, pdfFile.getNumPages());
pjob.setPageable(book); // Send print job to default printer
if (pjob.printDialog()) {
pjob.print();
return true;
}