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.