I'm trying to concatenate a huge number of PDF files to create a print-ready file, so that I don't have to print them one by one. The print-ready file I want needs to be duplex, so for the documents I have which are only 1 page, I need to add a blank page for the "back" of the document, otherwise the following document is messed up.
Is there any way to add blank pages while concatenating files using
PdfSmartCopy? I know
PdfWriter can easily add blank pages, but it isn't made for merging a large number of files, which is why I'm not using it. I've read the answer to the question "How to add blank pages in exist PDF in java?" However, in this case I can't use
PdfStamper either because I require a small file size and it seems
PdfSmartCopy is the only viable option for that, unless I have missed something.
Posted on StackOverflow on Jan 30, 2014
In my answer to the question you refer to, I explained how to insert a blank page into an existing PDF using
PdfStamper. This doesn't help you, because you're using
PdfSmartCopy, which is an extension of
PdfCopy. When using
PdfCopy (or its subclass
PdfSmartCopy), you can use the
addPage() method like this:
In this case, a page with size A4 will be added. In your case, you'd want to make sure that the blank page has the same dimensions as the other pages in your documents, so you'll do something like this:
Rectangle value will now correspond with the size of the first page in the reader; the
int value will correspond with the rotation of the first page of your existing document.