Skip to main content
Skip table of contents

How to merge PDFs from ByteArayOutputStreams?

I have two PDF files, each one in a ByteArrayOutputStream. I want to merge the two PDFs, and I want to use iText, but I don't understand how to do this because it seems that I need an InputStream (and I only have ByteArrayOutputStreams).

Posted on StackOverflow on Jan 13, 2014 by 3vi

The ByteArrayOutputStream object has a toByteArray() method that returns a byte[]. The PdfReader class has a constructor that takes a byte[] as parameter. Once you have a PdfReader instance of both files, you can use these instances with PdfCopy or PdfSmartCopy to merge the files. Use the Concatenate example for inspiration.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.