Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem most likely is some misconception on how <code>PdfStamper</code>works. You seem to think it somehow manipulates the data in the <code>PdfReader</code> it stamps, and also pages exported from that reader beforehand. This is <strong>not</strong> the case, a <code>PdfStamper</code> generates a new PDF file (in its output stream) based on the data in the reader but the contents of the reader itself are not updated to also reflect all the changes (the <code>PdfReader</code> object may be touched in the process, though, and not be reusable afterwards). So...</p> <p>As already mentioned in the comment, you have the <code>PdfConcatenate</code> and an unknown number of <code>PdfStamper</code> instances all writing the same `FileStream' output. As each of these objects creates an independant PDF, you are lucky if one of then wins because then you'll get at least a proper PDF as output. Otherwise you either get some exception or garbage consisting of multiple intermingled PDFs. Thus, make only PdfConcatenate target your output file.</p> <p>If your actual intent is to repeatedly fill the template fields with the content of 4 cards each time and combine the results, you should <strong>not</strong> add the pages from the <code>PdfReader</code> of the template to the <code>PdfConcatenate</code> --- the pages in that reader are not filled in! --- but instead have the PdfStamper output to a <code>MemoryStream</code>, fill its fields, flatten its form, close it, open its output in a new <code>PdfReader</code>, and add all the pages in that reader to the PdfConcatenate.</p> <p>I don't dare to put that into code as I'm predominantly using Java and writing down untested C# code most likely would include multiple errors... ;)</p> <p>PS: Currently you count on all the <code>PdfReader</code> instances you open to be implicitly closed somewhere. While that is true currently, recent check-ins in the iText SVN repository seem to indicate that these implicit close calls are removed from the code. Thus, please also start explicitly closing <code>PdfReader</code> instances you dont't use anymore. Otherwise you will soon have to deal with memory leaks due to readers closing much too late..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload