[Solved] IText 7 – Adding border for the page


The following piece of code allows you to draw red border around the specified page of your document. No hard-coding except page number.

PdfPage page = pdfDocument.getPage(1);
Rectangle pageRect = new Rectangle(page.getTrimBox());
new PdfCanvas(page).setStrokeColor(ColorConstants.RED).setLineWidth(5).rectangle(pageRect).stroke();

5

solved IText 7 – Adding border for the page