Convert a JPEG image to PDF document
Wednesday, 1 July 2009
I had the requirement to export data to a PDF document recently, which involved plotting data from a Domino database over an map that was stored in JPEG format.
The process I took was this:
- Extract the map from the Domino document to the file system
- Load the map in a Java agent using the java.awt.* package
- Plot the data on the map image
- Save the changes to the JPEG image on the file system
- Load the JPEG image again
- Slice the JPEG image into "pages"
- "Print" the sliced JPEG images into a PDF document
- Save the PDF document to the file system
- Use accordingly
I use step 5 because I built a custom script library to do the processing from that point forward so it seemed logical for code reusability to store the changes to disk.
Attached is the code for the script library to do the JPEG to PDF conversion.
It relies on an open source Java library freely available on the internet called gnujpdf. Google it, or click here.
File resource missing