Draw Rectangle using Apache PDFBox

Apache PDFBox is an open source java library used for manipulation of PDF’s. In this post we will see the steps on how to draw rectangle using Apache PDFBox.

We will be using below methods of org.apache.pdfbox.pdmodel.PDPageContentStream class

a) setNonStrokingColor(Color color)
Set the non-stroking color using an AWT color. Conversion uses the default sRGB color space.

b) addRect(float x, float y, float width, float height)
Adds a rectangle to the current path.
x – The lower left x coordinate.
y – The lower left y coordinate.
width – The width of the rectangle.
height – The height of the rectangle.

c) fill()
Fills the path using the nonzero winding number rule.


Lets see full example on the rectangle along with its output.

Draw Rectangle using Apache PDFBox

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn