I try to merge 2 PDF files into one PDF. I did it with PdfCopy.addPage(...) now I have good PdfCopy and I want to get it as byte array.
How can I do it? This is my code:
public void mergePDF(ActionEvent actionEvent) throws DocumentException, FileNotFoundException, IOException { String[] files = { "C:\\first.pdf","C:\sescond"}; Document document = new Document(); PdfCopy copy = new PdfCopy(document, new FileOutputStream("C:\\temp\\myMergedFile.pdf")); document.open(); PdfReader reader; int n; for (int i = 0; i < files.length; i++) { reader = new PdfReader(files[i]); n = reader.getNumberOfPages(); for (int page = 0; page < n; ) { copy.addPage(copy.getImportedPage(reader, ++page)); } copy.freeReader(reader); reader.close(); } document.close(); } Thanks.
soha