Adobe ColdFusion 8

Using cfhttp to display web pages

You can use the cfhttp tag in combination with the cfdocument tag to display entire web pages in PDF or FlashPaper output format, as the following example shows:

<!--- You can pass a URL in the URL string --->
<cfparam name="url.target_url" default="http://www.boston.com">
<cfoutput>
<cfhttp url="#url.target_url#" resolveurl="yes">

<cfdocument format="FlashPaper">
<cfdocumentitem type="header">
    <cfoutput>#url.target_url#</cfoutput>
</cfdocumentitem>
<cfdocumentitem type="footer">
    <cfoutput>#cfdocument.currentpagenumber# / #cfdocument.totalpagecount#</cfoutput>
</cfdocumentitem>
<!--- Display the page --->
#cfhttp.filecontent#
</cfdocument>
</cfoutput>

Using advanced PDF options

The cfdocument tag supports the Acrobat security options, as the following table shows:

Security option

Description

Encryption

Use the encryption attribute to specify whether PDF output is encrypted. Specify one of the following:

  • 128-bit
  • 40-bit
  • none

User password

Use the userpassword attribute to specify a password that users must enter to view the document.

Owner password

Use the ownerpassword attribute to specify a password that users must enter to view and optionally modify the document.

Additionally, the cfdocument tag supports the following Acrobat security permissions through the permissions attribute. Specify one or more of the following values; separate multiple permissions with a comma:

Permission

Description

Printing

Specify the AllowPrinting attribute to enable viewers to print the document.

Modification

Specify the AllowModifyContents attribute to let viewers modify the document, assuming they have the required software.

Copy

Specify the AllowCopy attribute to let viewers select and copy text from the document.

Annotation

Specify AllowModifyAnnotations to let viewers add comments to the document. If users add annotations, they must save the PDF after making changes.

Screen readers

Specify AllowScreenReaders to enable access to the document through a screen reader.

Fill in

Specify AllowFillIn to enable users to use form fields.

Assembly

Specify AllowAssembly to enable users to create bookmarks and thumbnails, as well as insert, delete, and rotate pages.

Degraded printing

Specify AllowDegradedPrinting to enable low-resolution printing. Low resolution printing prints each page as a bitmap, so printing may be slower.

Note: The defaults for these options vary, based on encryption level. These options apply to PDF only. For more information, see the cfdocument discussion in the CFML Reference.

The following example creates a PDF document that allows copying only:

<cfdocument format="PDF" encryption="40-bit"
    ownerpassword="us3rpa$$w0rd" userpassword="us3rpa$$w0rd"
    permissions="AllowCopy" >
<h1>Employee List</h1>
<cfquery name="EmpList" datasource="cfdocexamples">
    SELECT FirstName, LastName, Salary
    FROM Employee
</cfquery>
<cfoutput query="EmpList">
    #EmpList.FirstName#, #EmpList.LastName#, #LSCurrencyFormat(EmpList.Salary)#<br>
</cfoutput>
</cfdocument>

Saving printable reports in files

You can use the cfdocument filename attribute to save the generated PDF or SWF output to a file, as the following example shows:

<!--- The compasstravel database is part of the Getting Started
    tutorial application, found under the cfdocs directory. --->
<cfquery datasource="compasstravel" name="compasstrips">
SELECT tripName, tripDescription, tripLocation, price
FROM trips
ORDER BY price
</cfquery>
<cfdocument format="pdf"
        filename="#GetDirectoryFromPath(GetTemplatePath())#/compasstrips.pdf"
        overwrite="yes">
    <cfdocumentsection> 
        <h1 align="center">Compass Travel</h1>
        <h2 align="center">Destination Guide</h2>
        <p align="center"><img src="cfdocs/getting_started/photos/somewhere.jpg"></p>
    </cfdocumentsection> 
    <cfdocumentsection> 
        <cfdocumentitem type="header">
            <font size="-3"> <i>Compass Travel Trip Descriptions</i></font>
        </cfdocumentitem> 
        <cfdocumentitem type="footer"> 
            <font size="-3"> 
                <cfoutput>Page #cfdocument.currentpagenumber#</cfoutput>
            </font> 
        </cfdocumentitem> 
        <cfoutput query="compasstrips"> 
            <hr>
            <h2>#tripName#</h2>
            <p><b>#tripLocation#</b></p>
            <p>Price: #DollarFormat(price)#</p>
            <p>#tripDescription#</p>
        </cfoutput> 
    </cfdocumentsection> 
</cfdocument>