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.
// 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;
To use the UDF just pass it the fully qualified path to a PDF file, like this:
Obviously, XPAAJ must be present to use this UDF.
Leave a Reply