Monday, October 13, 2008    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Aug 2006 >>
S M T W T F S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Search

Categories
 • Acrobat (2) [RSS]
 • Adobe (68) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (25) [RSS]
 • AIR (134) [RSS]
 • Appearances (122) [RSS]
 • Books (69) [RSS]
 • CFEclipse (14) [RSS]
 • ColdFusion (1154) [RSS]
 • Data Services (13) [RSS]
 • Fish Tank (2) [RSS]
 • Flash (106) [RSS]
 • Flex (373) [RSS]
 • Home Automation (3) [RSS]
 • Jobs (97) [RSS]
 • JRun (13) [RSS]
 • Labs (27) [RSS]
 • LiveCycle (22) [RSS]
 • MAX (160) [RSS]
 • Regular Expressions (13) [RSS]
 • RIA (12) [RSS]
 • SQL (38) [RSS]
 • Stuff (505) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (137) [RSS]
 • Wireless (99) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
August 11, 2006

GetPDFInfo() UDF Returns PDF Information

A user wrote to ask how the recently released XPPAJ libraries (used in my cf_pdfform tag) could be used to determine basic PDF file information (version, page count, and so on). And yes, it sure can. The following is a quick UDF I threw together that returns PDF version, page count, attachment count, and a flag indicating whether or not the PDF contains a form.

<!--- Uses XPAAJ to return info about a PDF file --->
<cffunction name="GetPDFInfo" returntype="struct" access="public" output="no">
   <cfargument name="PDFFile" type="string" required="yes">

   <cfscript>
   // Init all vars
   var formIS="";
   var PDFfactory="";
   var PDFdoc="";
   var formType="";
   var attachments="";
   var result=StructNew();

   // PDF form input stream
   formIS=CreateObject("java", "java.io.FileInputStream");
   formIS.init(ARGUMENTS.PDFFile);

   // Get PDF document object
   PDFfactory=CreateObject("java", "com.adobe.pdf.PDFFactory");
   PDFdoc=PDFfactory.openDocument(formIS);

   // Get page count and version
   result.pages=PDFdoc.getNumberOfPages();
   result.version=PDFdoc.getVersion();

   // Get formtype object
   formType=PDFdoc.getFormType();   

   // Determine type
   if ((formType EQ FormType.XML_FORM)
      OR (FormType EQ FormType.ACROFORM))
      result.isform=TRUE;
   else
      result.isform=FALSE;

   // Get attachments
   attachments=PDFdoc.getFileAttachmentNames();
   // If have any, get count
   if (IsDefined("attachments") AND IsArray(attachments))
      result.attachments=ArrayLen(attachments);
   else
      result.attachments=0;
   </cfscript>

   <cfreturn result>
</cffunction>

To use the UDF just pass it the fully qualified path to a PDF file, like this:

<cfset PDFFile=ExpandPath("myPDFFile.pdf")>
<cfdump var="#GetPDFInfo(PDFFile)#">

Obviously, XPAAJ must be present to use this UDF.

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments
Using that information, as well as this blog post by Lori DeFurio, could be useful for some people: http://blogs.adobe.com/loridefurio/2005/12/adding_...

Mike
# Posted By Mike Potter | 8/11/06 11:11 AM
Thanks much for this. It's very helpful.

I do have a suggestion.

If all of the samples from the XPAAJ SDK were duplicated in .cfm instead of just .jsp, it would actually help both in teaching this subject to beginning Acrobat and ColdFusion developers as well as in presenting the new unified face of Adobe to the developer community.
Something that would be really useful is to be able to generate thumbnails of the first page of the PDF, I know it can be done with .net but a nice CFX tag would be awsome
# Posted By Richard Cooling | 8/23/06 12:05 PM
XPAAJ can't do that very easily (i.e. it's not a built-in method of that library).

The .NET libraries I've seen use JavaScript to call the addThumbnails method of the Doc Object using the full version of Acrobat running on a server. Although this could technically be accomplished easily enough in ColdFusion, I'm pretty sure Adobe's licensing policy (see http://www.adobe.com/aboutadobe/antipiracy/faq.htm...) for something like this would still prevent a server solution from doing this for modifying PDF's for delivery over the Internet. I'd love to be proven wrong on this, though.

One really cool thing I like about the XPAAJ.jar is that it doesn't even require Acrobat to be installed on the ColdFusion server and its my understanding that Adobe's licensing now lets anyone with a license for ColdFusion use this freely for Internet enabled apps.
# Posted By Sterling Ledet - Adobe Authorized training | 8/23/06 1:37 PM
Hi Ben,

I am trying to view the annotation names within the PDF. I can get the PDF instances by referencing:
   result.images=PDFdoc.getImages();

However, I cannot get the actual name or value of the annotation. I've tried:
   result.images=PDFdoc.getImages().toString();
but it seems to give me a memory reference, not the actual annotation value. Can you help?

Thanks!
# Posted By David | 8/31/07 11:51 AM

  © Copyright 1997-2008 Ben Forta, All Rights Reserved