How to add a border to a PDF page?

Tags: page eventspage borderrectangleiText 5

This is a snippet of my source code:

Rectangle rect= new Rectangle(36,108);
rect.enableBorderSide(1);
rect.enableBorderSide(2);
rect.enableBorderSide(4);
rect.enableBorderSide(8);
rect.setBorder(2);
rect.setBorderColor(BaseColor.BLACK);
document.add(rect);
Why am I not able to add border to my PDF page even after enabling borders for all sides? I've set border and its color too still I'm not able to add border.

Posted on StackOverflow on Jul 11, 2014 by user3819936

You didn't define a border width. You can fix this by adding:

rect.setBorder(Rectangle.BOX);
rect.setBorderWidth(2);

Note that I would remove the enableBorderSide() calls. You'll also notice that you've used the setBorder() method in the wrong way.