How to add a border to a PDF page?

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.setBord

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.


Share this article

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now