开发者

Making a paragraph in iText pdf not divided in two pages

开发者 https://www.devze.com 2023-03-26 01:21 出处:网络
I\'m writing a pdf file w开发者_StackOverflowith iText and I want the paragraphs divided across two different pages. How can I do this?It is a lot easier to help if you could provide a more accurate e

I'm writing a pdf file w开发者_StackOverflowith iText and I want the paragraphs divided across two different pages. How can I do this?


It is a lot easier to help if you could provide a more accurate example of the paragraphs and the document you are creating, but as far as I understand it is something like this:

Generate an ArrayList or other weapon of choise in making an iterable list of the paragraphs. Iterate through that list and call newPage() before adding content to page 2

 Document document = new Document();
 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream([file]));   

 for (ArrayList<Paragraph> : theParagraph ) {   
    document.addElement(theParagraph)
    document.newPage();

 }
 document.close();

This will automaticaly add new pages as content is added on the pdf-document, but with less controle over when the pagebreak occurs:

Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream([file])); 
document.open();
for(int i=0 ; i<100; i++){
    document.add(new Paragraph("This is a very important message"));
}
document.close();
0

精彩评论

暂无评论...
验证码 换一张
取 消