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.