How to add a new page between every page and then copy over to a new PDF. I know I am missing something basic, but am not seeming to get it down correctly.
int n = pdfReaderInput.NumberOfPages;
Document document = new Document();
PdfCopy copy = new PdfCopy(document, new FileStream(tempFile, FileMode.OpenOrCreate));
document.Open();
for (int i = 0; i < n; )
{
copy.AddPage(copy.GetImportedPage(pdfReaderInput, ++i));
}
document.Close();
return tempFile;
I understand and know this is wrong, but am not sure what I need to do. basically, I am adding a blank pdf in between every page. Thanks in advance!
When using PdfCopy
(or its subclass PdfSmartCopy
), you can use the addPage()
method like this:
copy.addPage(PageSize.A4, 0);
In this case, a page with size A4 will be added. If you want to make sure that the blank page has the same dimensions as another pages in your document (for instance page 1), you'll do something like this:
copy.addPage(reader.getPageSize(1), reader.getPageRotation(1));
The 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.
Update: I now see that you marked your question with the [itext] as well as the [itextsharp] tag. I answered it under the [itext] tag using Java code. It goes without saying that this answer is also valid for iTextSharp, but you'll need to make some minor updates to the syntax, for instance change addPage()
into AddPage()
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments