I am trying to edit a single-paged pdf like following:
loop until all content was used{ 1. copys the first page 2. add some content }
Right now, everything is working expect when I try to close both document and stamper I get an error that the first one was already closed.
Thing is:
if document was closed I can open it but there are only copies of pages, no content was added
If stamper was closed, the document is corrupt, but when I remove the document.NewPage() it workes, but only for the first page.
I tried creating a new instance of stamper in every iteration, but I get following error:
An unhandled exception of type 'iTextSharp.text.DocumentException' occurred in itextsharp.dll
Additional information: The original document was reused. Read it again from file.
I did close the stamper in every iteration, but it didn't help.
PdfStamperbecausePdfStamperchanges the underlyingPdfReaderwhile you alter the content of the existing PDF. You need to create a newPdfStamperfor every new output file. This is documented. See the FAQ entry on page 185 of chapter 6 of ye old iText in Action book. (Beats me why no one ever reads the documentation.) - Bruno Lowagie