/**
* Writes to <code>outputStream</code> the print of a home in PDF format.
*/
public void write(OutputStream outputStream) throws IOException {
PageFormat pageFormat = HomePrintableComponent.getPageFormat(this.home.getPrint());
Document pdfDocument = new Document(new Rectangle((float)pageFormat.getWidth(), (float)pageFormat.getHeight()));
try {
// Get a PDF writer that will write to the given PDF output stream
PdfWriter pdfWriter = PdfWriter.getInstance(pdfDocument, outputStream);
pdfDocument.open();
// Set PDF document description
pdfDocument.addAuthor(System.getProperty("user.name", ""));
String pdfDocumentCreator = this.preferences.getLocalizedString(
HomePDFPrinter.class, "pdfDocument.creator");
pdfDocument.addCreator(pdfDocumentCreator);
pdfDocument.addCreationDate();
String homeName = this.home.getName();
if (homeName != null) {
pdfDocument.addTitle(this.controller.getContentManager().getPresentationName(
homeName, ContentManager.ContentType.PDF));
}
PdfContentByte pdfContent = pdfWriter.getDirectContent();
HomePrintableComponent printableComponent =
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();