ByteArrayOutputStream object has a
toByteArray() method that returns a
byte which can be used in the
InputStream constructor. In iText 7 the
PdfReader class has a constructor that takes an
InputStream as parameter.
PdfReader reader = new PdfReader(new ByteArrayInputStream(baos.toByteArray()));
Once you have a
PdfReader instance of both files, you can create
PdfDocument objects and use
PdfDocument pdfDoc = new PdfDocument(reader); pdfDoc.copyPagesTo(1, pdfDoc.getNumberOfPages(), pdfDocResult);
The last parameter is the resulting PDF (
Have a look at the Concatenate example for inspiration.
Click this link if you want to see how to answer this question in iText 5.