I am trying to concatente my selfmade text in itext with other already completed pdf. The problem is that when i concatenate two pdfs the second one starts from new page, he is not merging with the other pdf.
public static void main(String[] args) throws DocumentException, IOException {
String[] files = new String[]{"FirstPdf.pdf","SecondPdf.pdf"};
Document document = new Document();
PdfCopy copy = new PdfCopy(document, new FileOutputStream("PdfConcatenation.pdf"));
document.open();
for (String file : files){
PdfReader reader = new PdfReader(file);
for (int i = 1; i <= reader.getNumberOfPages(); i++){
// optionally write an if statement to include the page
copy.addPage(copy.getImportedPage(reader, i));
}
copy.freeReader(reader);
reader.close();
}
document.close();
}
i am expecting "SecondPdf" text to be straight after the "FirstPdf" text...