How to add blank pages to an existing PDF in java?

I have a normal PDF file, I want to insert blank pages at the end of this PDF using iText, without changing the existing PDF contents.

Posted on StackOverflow on May 24, 2013 by khAn

Please try this short code snippet:

PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
int index = pdfDoc.getNumberOfPages();
PageSize ps = new PageSize(pdfDoc.getFirstPage().getPageSize());
pdfDoc.addNewPage(index + 1, ps);

If src refers to a document with 10 pages, the code above will add an extra blank 11th page, using the same page size as the first page. You can specify any index and ps values. If you don't need these settings, iText 7 provides a simple method:


Click this link if you want to see how to answer this question in iText 5.

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now