Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a new page in PDF using itext 7

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();
like image 948
Karthick Radhakrishnan Avatar asked Nov 29 '16 06:11

Karthick Radhakrishnan


People also ask

How do I add a cover page to a PDF?

Open your e-book PDF. Select "Document," "Pages" and then "Insert." Go to "Insert Dialogue" and click "Select." Select your jpeg cover image. Choose where in the e-book file you want your cover graphic to appear, when the "Insert Pages Dialogue" box appears.

Is iText PDF free?

This license is a commercial license. You have to pay for it. To answer your question: iText can be used for free in situations where you also distribute your software for free. As soon as you want to use iText in a closed source, proprietary environment, you have to pay for your use of iText.

Is iText same as iTextSharp?

iTextSharp is the name of the iText 5 PDF library for .


1 Answers

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...]
like image 177
mkl Avatar answered Sep 20 '22 18:09

mkl