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.
Mike
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.
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.
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!