Managing PDF document information

To retrieve information stored with a source PDF document, such as the creation date, the application used to create the PDF document, and the name of the person who created the document, use the getInfo action. For a list of data elements, see PDF file information elements in the CFML Reference.

Use the setInfo action to specify information, such as the author, subject, title, and keywords associated with the output file. This information is useful for archiving and searching PDF documents. PDF document information is not displayed or printed with the document.

The following example shows how to set keywords for tax documents. The information is useful for assembling the documents based on the tax filing requirements for different business types (Sole Proprietor, Partnership, and S Corporation). Some business types share the same forms and documents. By setting the business type keywords for each document, you can store the documents in one directory and search them based on keyword values. The following code sets three keywords for the p535.pdf tax booklet:

<cfset taxKeys=StructNew()> 
<cfset taxKeys.keywords="Sole Proprietor,Partnership,S Corporation"> 
<cfpdf action="setInfo" source="taxes\p535.pdf" info="#taxKeys#" 
    destination="taxes\p535.pdf" overwrite="yes">

When you use the setInfo action, ColdFusion overwrites any existing information for that key-value pair. In the previous example, if the pc535.pdf document contained a keyword of “tax reference”, ColdFusion overwrites that keyword with “Sole Proprietor, Partnership, S Corporation”.

To retrieve all of the information associated with the tax file, use the cfdump tag with the getInfo action, as the following example shows:

<cfpdf action="getInfo" source="taxes\p535.pdf" name="taxInfo"> 
<cfdump var="#taxInfo#">

To retrieve just the keywords for the PDF document, use this code:

<cfpdf action="getInfo" source="taxes\p535.pdf" name="taxInfo"> 
<cfoutput>#taxInfo.keywords#</cfoutput>