List of usage examples for com.lowagie.text.pdf PdfWriter setPageLabels
public void setPageLabels(PdfPageLabels pageLabels)
From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFManager.java
License:Apache License
/*************************************************************************** * Creates a PDF, which is streams to the OutputStream out. * /*from w ww . j ava2s . co m*/ * @param out {@link OutputStream} * @param pagesizemode {@link PdfPageSize} * * * @throws IOException Signals that an I/O exception has occurred. * @throws FileNotFoundException the file not found exception * @throws ImageManagerException the image manager exception * @throws PDFManagerException the PDF manager exception * @throws ImageInterpreterException the image interpreter exception * @throws URISyntaxException ****************************************************************************/ public void createPDF(OutputStream out, PdfPageSize pagesizemode, Watermark myWatermark) throws ImageManagerException, FileNotFoundException, IOException, PDFManagerException, ImageInterpreterException, URISyntaxException { Document pdfdoc = null; PdfWriter writer = null; Rectangle pagesize = null; // pagesize of the first page PdfPageLabels pagelabels = null; // object to store all page labels try { if ((imageURLs == null) || (imageURLs.isEmpty())) { throw new PDFManagerException("No URLs for images available, HashMap is null or empty"); } // set the page sizes & pdf document pdfdoc = setPDFPageSizeForFirstPage(pagesizemode, pagesize); // writer for creating the PDF writer = createPDFWriter(out, pdfdoc); // set metadata for PDF as author and title // ------------------------------------------------------------------------------------ if (this.title != null) { pdfdoc.addTitle(this.title); } if (this.author != null) { pdfdoc.addAuthor(this.author); } if (this.keyword != null) { pdfdoc.addKeywords(this.keyword); } if (this.subject != null) { pdfdoc.addSubject(this.subject); } // add title page to PDF if (pdftitlepage != null) { // create a title page pdftitlepage.render(pdfdoc); } // iterate over all files, they must be ordered by the key // the key contains the page number (as integer), the String // contains the Page name // ---------------------------------------------------------------------- pagelabels = addAllPages(pagesizemode, writer, pdfdoc, myWatermark); // add page labels if (pagelabels != null) { writer.setPageLabels(pagelabels); } // create the required xmp metadata // for pdfa if (pdfa) { writer.createXmpMetadata(); } } catch (ImageManagerException e) { if (pdfdoc != null) { pdfdoc.close(); } if (writer != null) { writer.close(); } throw e; } catch (PDFManagerException e) { if (pdfdoc != null) { pdfdoc.close(); } if (writer != null) { writer.close(); } throw e; } catch (ImageInterpreterException e) { if (pdfdoc != null) { pdfdoc.close(); } if (writer != null) { writer.close(); } throw e; } catch (IOException e) { if (pdfdoc != null) { pdfdoc.close(); } if (writer != null) { writer.close(); } throw e; } // close documents and writer try { if (pdfdoc != null && pdfdoc.isOpen()) { pdfdoc.close(); } if (writer != null) { writer.close(); } } catch (IllegalStateException e) { LOGGER.warn("Caught IllegalStateException when closing pdf document."); } catch (NullPointerException e) { throw new PDFManagerException("Nullpointer occured while closing pdfwriter"); } LOGGER.debug("PDF document and writer closed"); }