I\'ve a requirement, where I am generating different pdf\' using iText 7.1.11
. I am using PdfMerger
to merge all pdf\'s on the fly. I am able to genera
This is how you initialize your PdfMerger
:
PdfWriter writer = new PdfWriter(dest); // 'dest' is local file system path
PdfDocument pdf = new PdfDocument(writer);
PdfMerger merger = new PdfMerger(pdf);
I.e. you explicitly write to the local file system and even stress that fact in the comment.
If you want to have the merged PDF in a byte[]
at the end, why don't you simply use a ByteArrayOutputStream
here (as you claim you have tried a few lines earlier):
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PdfWriter writer = new PdfWriter(byteArrayOutputStream );
PdfDocument pdf = new PdfDocument(writer);
PdfMerger merger = new PdfMerger(pdf);
...
pdf.close();
byte[] bytes = byteArrayOutputStream.toByteArray();