How to remove margin of a new pdf created using PdfDocument object in iText?

546 Views Asked by At

As per my previous question, I am trying to merge multiple pdf pages into a single page. I am able to convert multiple pages pdf file to a merged pdf file. But default margin is cutting my document after merging.

I tried adding Document object also. But somehow I am unable to remove margin.

Document tempDoc = new Document(pdfDoc, pageSize);
tempDoc.setMargins(0, 0, 0, 0);

Sample code

PdfDocument srcDoc = new PdfDocument(new PdfReader(src));
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
pdfDoc.setDefaultPageSize(pageSize);
PdfCanvas canvas = new PdfCanvas(pdfDoc.addNewPage());

//logic of pdf manipulation
PdfFormXObject page = srcDoc.getPage(pageCount).copyAsFormXObject(pdfDoc);
canvas.addXObject(page, xPos, yPos);

canvas = new PdfCanvas(pdfDoc.addNewPage());

Please suggest if I am doing something wrong or is there any other way to remove margin using PdfDocument object.

0

There are 0 best solutions below