I am trying to read one PDF file and copy its data to another PDF file. The first PDF file contains text and images, and I want to write the image in the second PDF, where the text ends (which is basically the end of the PDF file). RIght now it just prints at the top. How to do it?
PdfReader reader = null; reader = new PdfReader(Var.input); Document document=new Document(); PdfWriter writer = null; writer = PdfWriter.getInstance(document,new FileOutputStream(Var.output)); PdfImportedPage page = writer.getImportedPage(reader, 1); reader.close(); document.open(); PdfContentByte cb = writer.getDirectContent(); // Copy first page of existing PDF into output PDF document.newPage(); cb.addTemplate(page, 0, 0); // Add your new data / text here Image image = null; image = Image.getInstance (Var.qr); document.add(image); document.close();
source share