Here is a sample code to open an image file in Qoppa’s Java PDF Components jPDFNotes and jPDFEditor which will convert it on the fly to PDF. The generated document can then be annotated in the component and then saved as PDF as any other PDF.

pdfNotesBean = new PDFNotesBean();
try
{
// open a JPG file, which is immediately converted to PDF on the fly
 pdfNotesBean.loadDocument("C:\\MyFolder\\sample.jpg");
// here users can annotate the PDF file in the PDFNotesBean
....
 // Save the output PDF
 pdfNotesBean.saveDocument("C:\\MyFolder\\sample.pdf");
//pdfNotesBean.close(false); 
}
catch(Throwable t)
{ 
 t.printStackTrace();
}

What are the image format supported?

  • GIF (*.gif)
  • PNG (*.png)
  • TIFF (*.tif, *.tiff)
  • JPEG (*.jpg, *.pjpeg, *.jpe)
  • JPEG 2000 (*.jp2, *.j2c, *.j2k, *.jpx)

Note that as of v2016R1, JPEG200 images can be loaded as BufferedImage and added as pages. We will soon enhance our file extension parsing code to recognize the JPEG200 extensions by default and allow the to be opened directly from the bean.

JAI jars may be required

To load TIFF or JPEG200 files, make sure to include the JAI files in your classpath

  • jai_imageio.jar – This jar file contains Java’s ImageIO image decoders, including a decoder for JPEG 2000 images. This is only used when a document contains JPEG 2000 images.
  • jai_codec.jar – This jar file contains additional image encoders / decoders for ImageIO, it is necessary when opening TIFF files for display in jPDFNotes.

Otherwise, you may get the exceptions such as:

com.qoppa.pdf.PDFException: no reader for for TIFF files.
at com.qoppa.b.c.b(Unknown Source)
at com.qoppa.b.c.h(Unknown Source)
at com.qoppa.pdfNotes.e.i.b(Unknown Source)
at com.qoppa.pdfNotes.PDFNotesBean.loadDocument(Unknown Source)