Icepdf Alternative to CFPDF for High Resolution PDF Thumbnails

Andrew Schwäbe
PainInTheApps
Published in
2 min readNov 25, 2012

I ran into the same problem that many have with generating high resolution thumbnails from a PDF file. Using CFPDF, the options for scale and high resolution do nothing. The reason is that the included jpedal java library doesn’t have the included support for high resolution export. For those of you who have this problem and are as frustrated as I was, here is an option that worked for me.

I tried every which way to leverage the built-in jpedal and in the end I downloaded the trial version from jpedal and using that directly was able to generate higher quality output. It takes some trickery to load the java class so it doesn’t conflict with the built in jpedal and isn’t nearly as easy as it should be. The problem with this of course is that it is trial software that you need to purchase. Between $800 and $9000 to buy, so not a viable option for the indie coders out there.

I looked deeper into the Railo java libaries and found that IcePdf is included. I suspect it is used to generate PDFs with cfdocument and other methods, however IcePdf has support built in to do what we want. Here’s a step-through of accomplishing the same high res thumbnail output using the icepdf included with Railo, and I suspect is in Adobe’s flavor. If not, download it for free.

First we instantiate the icepdf Document class:


We will need two other classes as well. Don’t even bother reading up on them unless you really want to understand the underlying logic :



Now initialize the document object passing in your PDF’s path and filename:
<cfset objPdf.setFile(“#expandpath(“/your/path/to”)#/your.pdf”)>

Now create a java buffered image containing the rendering of the requested page


Where “pageNumber” contains the number of the page you want, and zoomFactor is an integer representing the scale you want. 1 = 100%; 2 = 200%, 2.5 = 250% and so on. These end up being *approximate* so experiment until you get the scale you want.

Now we use ImageNew() to convert the BufferedImage into a CFIMAGE:


Now write the image out to disk:


There you go, output considerably better than CFPDF action=”thumbnail” output for $0.

If this was helpful, give a shout out, or hug a baby or something nice like that.

--

--

Andrew Schwäbe
PainInTheApps

I’m an Artificial Intelligence, blockchain, crypto type of guy. Oh, and guitarist. And foodie. And philanthropist. Maybe more, check back later.