Adding a new page in PDF using itext 7

20,815

In iText 7 the newPage method has become a special case of an area break:

Document document = ...;
[....add some content...]
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
[...add some content on next page...]
Share:
20,815

Related videos on Youtube

Karthick Radhakrishnan
Author by

Karthick Radhakrishnan

Updated on July 09, 2022

Comments

  • Karthick Radhakrishnan
    Karthick Radhakrishnan almost 2 years

    I'm trying to create a PDF Document using iText 7 with below code and my PDF documents contents are overlapping in same page when generated.(i.e in Page 1).

    I see the

    document.newPage();

    method is missing in iText 7. How can i add pages to my PDF document without using pdfDocumet.copyPages(...) or PDFmerger in itext 7.

            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));      
            pdfDoc.addNewPage();
            Document PageOnedocument = new Document(pdfDoc,PageSize.A4);            
            addPageOneContents(PageOnedocument);  
    
    
            pdfDoc.addNewPage();
            Document PageTwodocument = new Document(pdfDoc,PageSize.A4);            
            addPageTwoContents(PageTwodocument);  
    
            pdfDoc.close();
            PageOnedocument.close();
            PageTwodocument.close();
    
  • AllirionX
    AllirionX over 4 years
    Is this documented somewhere?
  • mkl
    mkl over 4 years
    @AllirionX In itextpdf.com/en/resources/books/itext-7-building-blocks/… - but it is a bit hidden among more complex AreaBreak usages.
  • AllirionX
    AllirionX over 4 years
    Thanks! It's very useful, I was getting mad trying to add a simple paragraph to a new page.