Creat a JPG image file from a PDF file

I have seen this thread

I am interesting with creating images from PDF files.

But I do not understand what is needed to do this.
Do I need something like PDFBOX ? or is it implemented in Lucee
Is there a complete documentation to be able to do this ?
I am starting from scratch. I just have Lucee and a PDF file. Then I do not know what to do.
I have lucee- on Linux debian 10 and Apache 2

Thanks to help.
on a site, Users are uploading PDF file to show the image, but it is not rendered by the browser.
And the PDF file is 10 time more heavy than a JPG file.
Then I need to automate the conversion.

When it can work, can i use a coding like this
cfset im=convertPdfPageToImage(‘mypdf.pdf’)
Then the JPG will be created somewhere. (same directory, if not specified ?)
(I do not use cfscript )

If you want to use PDFBox to do this, you will need at least the following 2 jar files:

  • pdfbox-[version_number].jar
  • fontbox-[version_number].jar

I don’t remember if/what Lucee ships with in its bundles, but you can find built jar files at online repositories like

Last year, I wrote an article on using PDFBox to do exactly this, along with an async solution to speed things up (there can be some overhead on multipage files). The article uses PDFBox 2.x, but I also have a GitHub repository that uses 3.x.

It’s all in cfscript, though I see you said you don’t use it, but hopefully it can give you an idea on how to get started. The example code also makes use of CommandBox, but that’s certainly not a requirement.

Hope that helps.

I have found these jar
there are others called “standalone” , I presume the first one are the good one for the Lucee server. (from site : Apache PDFBox | Download, a version 2 also exists )
Should I put these files in Lucee directory and restart Lucee ?
Which directory
lucee/tomcat/bundles ?

Thanks for this first approach.

Those 2 look like the latest releases, so that should be fine. Version 3 is not a “stable” release yet, so expect there to be more updates sooner than later.

Just know if you switch between version 2 and 3, the code for loading a PDF into the library is slightly different. Version 2 uses the PDDocument class, version 3 uses the Loader class.

I am pretty sure you can place them in lucee/lib, but admittedly I have not used that approach in a long time, so I’m not aware of any caveats. I usually place jar files in a /lib folder within the project and map the directory using this.javasettings in Application.cfc.

Thanks, I will try next time I restart Lucee.
(production with Linux, and on local , I am on windows).

<cfpdf action="thumbnail" scale="1-100" etc>

1 Like