Saving to file before merging is giving different results than merging before saving

I’ve got three PDF templates that I’m manipulating in memory as ByteArrayOutputStreams, and then I convert those to ByteArrayInputStreams, and I need to merge them together. There’s the header template, the body template, and the trailer page template. However, for each template, after they’ve been populated with data, I need to insert bar codes into the document so that they can be automatically scanned elsewhere. There are form fields on the templates, and I call a pdfForm.fillImageField() to put an all-black bar image in that field when needed.


Now here’s where I’m stumped. After adding the bar codes to each template, if I save those PDFs out to files (header.pdf, main.pdf, and footer.pdf) and then make new Document objects from those files, I can call pdf1.getPages().add(pdf2.getPages()) and then call pdf1.save(), and it will work fine. If I skip the part where I write out to files and re-initialize, using the same Document objects I was using before, the bar codes won’t show up in the final document, but the file size is large enough that it seems like they should be there.

Any ideas? A coworker and I have been scratching our heads over this for weeks now.

Hi Andrew,


Thanks for your inquiry. Please note PDF document is created dynamically by API and in order to get real PDF document it needs to render its programming/dynamic model. So we can render PDF document model by calling save() or without saving using processParagraphs() method. So you may use processParagraphs() to render PDF document structure without calling save(), hopefully it will resolve the issue. If the issue persist then please share your sample code along with documents, we will look into it and guide you accordingly.

//open document<o:p></o:p>

Document pdfDocument = new Document();<o:p></o:p>

…<o:p></o:p>

…<o:p></o:p>

pdfDocument.processParagraphs();


Please feel free to contact us for any further assistance.

Best Regards,