Add Image in PDF using Apache PDFBox

Apache PDFbox is an open source java library used for manipulation of PDF’s. In this post we will see how to Add Image in PDF using Apache PDFBox.

Class – PDImageXObject

For creating an image in the PDF file, PDImageXObject class is used. The commonly used methods of this class are
a) createFromFile(String imagePath, PDDocument doc)
b) createFromFileByContent(File file, PDDocument doc)
c) createFromFileByExtension(File file, PDDocument doc)
d) setHeight(int h)
e) setWidth(int w)

For adding the image that was created using above methods, PDPageContentStream.drawImage() is used.

Now we will use few of these methods and create a simple pdf file with image.

Output

Add Image in PDF using Apache PDFBox

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