Leena Kulkarni wrote: > Hello Bruno, > I checked th emailing list for help on Page no. > Also tried the following link. > http://itextdocs.lowagie.com/examples/com/lowagie/examples/directcontent/pageevents/PageNumbersWatermark.java
That's a good example, if you know what you are doing. > Actually, we are generating XML file on the fly before generating the PDF. > The code is like following: I'll add some comments, but you should rewrite it completely. The code is beyond debugging. > //Form an XML String by concatenating xml tags and data in StringBuffer > //Prepare InputSource object > InputSource is2 = new InputSource(new > StringReader(sampleXMLString.toString())); > //create document > Document document = new Document(PageSize.A4, 80, 50, 30, 65); > //In try catch - the following: > PdfWriter writer = PdfWriter.getInstance(document, baosPDF); If you want to set events, set them immediately after you created the writer instance. > XmlParser.parse(document, is2); The line above parses the XML and adds content to the document. The page events will have no effect if you add it afterwards. > //The I put the example code: > writer.setPageEvent(new PageNumbersEventHelper()); What is documentB??? > documentB.open(); What do you intend to do with the following lines? > // step 4: adding content > String text = "Page "; > for (int k = 0; k < n; ++k) > text += text; > Paragraph p = new Paragraph(text); > //p.setAlignment(Element.ALIGN_JUSTIFIED); > document.add(p); ??? > // step 5: closing the document > document.close(); What happened with documentB??? > But I am getting error that document is already closed. Of course: document was already closed when the parser encountered the closing tag of the root XML element. > 1. Can you please help as to how to put the page nos? Please have a look at this example: http://itextdocs.lowagie.com/tutorial/directcontent/pageevents/index.html#romeojuliet > 2. Is the approach right when using the XML String? I'm sorry, but you have patched unrelated lines of code together that will never compile; it doesn't work that way. > 3. If not, can you give us some direction? If there is no specific reason to generate the XML before generating the PDF, I would drop all the XML mumbo-jumbo. br, Bruno ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
