![java pdfwriter java pdfwriter](https://www.reportmill.com/product/Edit.jpg)
I'm always disappointed when I read "we are using iText 2.1" because that's really not a wise choice as explained here, but this is a question about design, so here is a possible approach: Could this be done using only a single stamper? Could it be done without using a rotating series of buffers? Lowagie's response suggests that there is a simpler or more direct way to use PdfStampers, though I do not quite understand it myself yet. "Abusing" the PdfStamper by creating and closing the stamper too many times can cause corruptions in the resulting file that only effect some programs, generating a seemingly good document that may fail in certain contexts.
JAVA PDFWRITER CODE
However, as discovered through this Stack Overflow question (where example code can also be viewed) and the response by iText author Bruno Lowagie, this methodology of using the PdfStamper can cause significant issues. Here is a diagram visually explaining the above process, which is performed for each iteration of the "loop" that performs each template: Swaps the "storage buffer" with the "working buffer" in order to be ready to repeat.Imports the page from the "template buffer," adds it to the ContentByte of the PdfStamper.Closes the PdfReader, opens a new PdfReader to the "template buffer".Creates a PdfStamper that reads from the PdfReader and writes to a "storage buffer".Creates a PdfReader to read a "working buffer" that stores the current final document in progress.
![java pdfwriter java pdfwriter](http://www.softsea.com/screenshot/image/J2P-Java-to-PDF.jpg)
JAVA PDFWRITER PDF
We at the company I work for are attempting to create complex PDF files using Java iText (the free version 2.1 line). EDIT: Updated flow diagram to better explain the (likely unnecessary) complexity of what I'm doing.