Skip to main content
Skip table of contents

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

Click this link if you want to see how to answer this question in iText 7.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.