private void createWriter ( Document document , String title ) throws DocumentException , IOException { final PdfWriter writer = PdfWriter . getInstance ( document , output ) ; //writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft); // title final HeaderFooter header = new HeaderFooter ( new Phrase ( title ) , false ) ; header . setAlignment ( Element . ALIGN_LEFT ) ; header . setBorder ( Rectangle . NO_BORDER ) ; document . setHeader ( header ) ; // simple page numbers : x //HeaderFooter footer = new HeaderFooter(new Phrase(), true); //footer.setAlignment(Element.ALIGN_RIGHT); //footer.setBorder(Rectangle.TOP); //document.setFooter(footer); // add the event handler for advanced page numbers : x/y writer . setPageEvent ( new PdfAdvancedPageNumberEvents ( ) ) ; }
We create a writer that listens to the document and directs a PDF - stream to output