iText is a free and open source library for creating and manipulating
PDF documents in Java. The following example shows setting document border of a PDF document.
//Create layout and set background & borders
Rectangle layout = new Rectangle(PageSize.A4);
layout.setBackgroundColor(new BaseColor(100, 200, 180)); //Background color
layout.setBorderColor(BaseColor.DARK_GRAY); //Border color
layout.setBorderWidth(6); //Border width
layout.setBorder(Rectangle.BOX); //Border on 4 sides
Document document = new Document(layout);
PdfWriter.getInstance(document, new FileOutputStream("test8.pdf"));
//Open the document before adding any content
document.open();
Paragraph paragraph = new Paragraph("BE THE CODER");
document.add(paragraph);