I have an existing pdf file, and I want to add a new content to it in top of the same existing pdf page. The problem with the following code is I get a pdf file where the new content is over the old content (old content doesn't move it keeps its position & they got mixed) and the generated file is not readable. Please any idea how can I make this possible
public byte[] pdfCreation(Port port, byte[] oldPdf) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayInputStream bais = new ByteArrayInputStream(oldPdf);
PdfReader reader = new PdfReader(bais);
PdfWriter writer = new PdfWriter(baos);
PdfDocument pdfDoc = new PdfDocument(reader, writer);
Document document = new Document(pdfDoc);
float[] columnWidth = { 200f, 200f, 200f, 200f };
Table table = new Table(columnWidth).setCaption(new Div().add(new Paragraph("My caption").setBold()));
table.addCell(new Cell().add(new Paragraph("id")));
table.addCell(new Cell().add(new Paragraph("description")));
table.addCell(new Cell().add(new Paragraph(new StringBuilder().append(port.getId()).toString())));
table.addCell(new Cell().add(new Paragraph(port.getDescription())));
document.add(table);
document.close();
byte[] pdf = baos.toByteArray();
return pdf;
}