Login

    Register

Managed Hosting

PROJECT CATEGORIES

 

PDFUtils
Project Home Known Issues Contact Project

PDFUtils Issue: Error in getPage method

Name: Error in getPage method
ID: 2
Project: PDFUtils
Type: Enhancement
Area: Code
Severity: Low
Status: Fixed
Related URL:
Creator: Matt Currier
Created: 04/09/10 11:29 AM
Updated: 04/13/10 9:28 AM
Description: Very useful library! I learned a lot from it...

I have a system that extracts each page into a separate PDF that must handle PDFs from 1-N pages. "getPage" fails to extract Page 1 from a 1 page PDF (range becomes 1-0). Here is my fix:


   <cffunction name="getPage" access="public" returnType="any" output="false" hint="I return one page of a PDF file as a PDF.">
      <cfargument name="pdf" type="any" required="true" hint="The PDF. Either a filename or pdf var.">
      <cfargument name="page" type="numeric" required="true" hint="Page number to get.">

      <cfset var info = "">
      <cfset var result = "">

      <!--- get info on the pdf --->
      <cfpdf action="getinfo" name="info" source="#arguments.pdf#">

      <cfif info.totalpages lt arguments.page>
         <cfthrow message="#arguments.pdf# only has #info.totalpages#. Cannot get page #arguments.page#">
      </cfif>

      <!---
      We need to tell cfpdf to delete everything BUT N. So we make a string to represent this.
      --->
      <cfif info.totalPages EQ 1>
         <cfpdf action="read" source="#arguments.pdf#" name="result">
      <cfelse>
         <cfif arguments.page is 1 and info.totalpages gte 2>
            <cfset range = "2-#info.totalpages#">
         <cfelseif arguments.page lt info.totalpages>
            <cfset range = "1-#arguments.page-1#,#arguments.page+1#-#info.totalpages#">
         <cfelse>
            <cfset range = "1-#arguments.page-1#">
         </cfif>
   
         <cfpdf action="deletePages" source="#arguments.pdf#" pages="#range#" name="result">
      </cfif>

      <cfreturn result>
   </cffunction>
History: Created by fingerskier (Matt Currier) : 04/09/10 11:29 AM

Updated by cfjedimaster (Raymond Camden) : 04/13/10 9:28 AM
Thank you. It is fixed!

To add a comment to this bug, please login using the link above.