Legacy notice!

iText 5 is the previous major version of iText's leading PDF SDK. iText 5 has been EOL, and is no longer developed. Switch your project to iText 7, integrating the latest developments.
Check related iText 7 content!

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.