new HomePrintableComponent(this.home, this.controller, this.defaultFont);
// Print each page
for (int page = 0, pageCount = printableComponent.getPageCount(); page < pageCount; page++) {
// Check current thread isn't interrupted
if (Thread.interrupted()) {
throw new InterruptedIOException();
}
PdfTemplate pdfTemplate = pdfContent.createTemplate((float)pageFormat.getWidth(),
(float)pageFormat.getHeight());
Graphics g = pdfTemplate.createGraphicsShapes((float)pageFormat.getWidth(),
(float)pageFormat.getHeight());
printableComponent.print(g, pageFormat, page);
pdfContent.addTemplate(pdfTemplate, 0, 0);
g.dispose();
if (page != pageCount - 1) {
pdfDocument.newPage();
}
}
pdfDocument.close();
} catch (DocumentException ex) {
IOException exception = new IOException("Couldn't print to PDF");
exception.initCause(ex);
throw exception;
} catch (InterruptedPrinterException ex) {
throw new InterruptedIOException("Print to PDF interrupted");
} catch (PrinterException ex) {
IOException exception = new IOException("Couldn't print to PDF");
exception.initCause(ex);
throw exception;
}