4

Right now i use iText to generate a pdf automatically. And my problem is that when the content is really very large, i need to calculate the content's height and width, and then add new page... this is really very inconvinent.

so I wonder whether or not there is a method like: Document.add("a very very large article"); and after this , it will auto generate a pdf file ????

Thanks in advance !

3
  • Asking myself the same question. Commented Aug 14, 2009 at 14:38
  • What sort of "content" are you trying to add? Commented Aug 27, 2009 at 21:06
  • In your program, wrap the lines of code which add the content in a for(int i = 0; i < 100; i++) loop and try generating the PDF. If things are set up properly, you will notice that iText has created a multi-page PDF. Commented Nov 8, 2009 at 9:05

2 Answers 2

5

The following creates a 9 page pdf without having to calculate height and width.

import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter; public class HelloWorld { public static void main(String[] args) { Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf")); document.open(); String text = ""; for (int i = 0; i < 10000; i++) { text += "test"; } document.add(new Paragraph(text)); } catch (DocumentException e) { System.err.println(e.getMessage()); } catch (IOException ex) { System.err.println(ex.getMessage()); } document.close(); } } 
Sign up to request clarification or add additional context in comments.

Comments

0

a new page will be generated automaticly, when the content of the current page is full.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.