Getting a page from a PDF Document in ColdFusion 8

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”> </code>

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.<p>Download attached file.</p>

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for Extend by Auth0. He focuses on serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments