Getting a page from a PDF Document in ColdFusion 8

This post is more than 2 years old.

Every needed to extract a page from a PDF document? Yesterday I blogged my new little CFC called PDFUtils. The idea was to take the power of CFPDF and wrap up some utility functions. The first function contained a simple getText() utility that would return all the text in a PDF.

Today I added getPage(). As you can guess, it grabs one page from a PDF. How? Well CFPDF doesn't support getting one page, but it does support deleting pages. All I did was add logic to "flip" a page number into a delete order. This then lets you do:

<cfset pdf = createObject("component", "pdfutils")>

<cfset mypdf = expandPath("./paristoberead.pdf")>

<cfset page2 = pdf.getPage(mypdf, 2)> <cfdump var="#page2#">

<cfpdf action="write" source="page2" destination="page2.pdf" overwrite="true">

Running this gets you a dump of the PDF object and a new file named page2.pdf that is just - you guessed it - page 2.

I've reattached the code plus sample files and PDFs.

Download attached file.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA