cfdocument

Description

Creates PDF or FlashPaper output from a text block containing CFML and HTML.

Categories

Related

History

ColdFusion 9: Add ppt support to the srcFile attribute. Added the following attributes to support conversion of a Word document to PDF or HTML using OpenOffice libraries:formfields attribute formsType attribute openpassword attribute permissionspassword attribute pdfa attribute tagged attribute ColdFusion 8: Added the following attributes and variables: bookmark attribute localUrl attribute Ability to embed existing PDF forms by using the cfpdfform tag in the cfdocument tag. ColdFusion determines the MIME type of a source file based on the source filename, if the mimeType attribute is not specified. Ability to pass a PDF variable created with the cfdocument tag as the source for the cfpdf tag. authPassword, authUser, proxyHost, proxyPassword, proxyPort, proxyUser, and userAgent attributes saveAsName attribute totalsectionpagecount and currentsectionpagenumber scope variables. ColdFusion MX 7.01: Added the src, srcfile, and mimetype attributes. ColdFusion MX 7: Added this tag.

Syntax

<cfdocument 
    format = "PDF|FlashPaper" 
    authPassword = "authentication password" 
    authUser = "authentication user name" 
    backgroundVisible = "yes|no" 
    bookmark = "yes|no" 
    encryption = "128-bit|40-bit|none" 
    filename = "filename" 
    fontEmbed = "yes|no" 
    formfields = "yes|no" 
    formsType = "FDF|PDF|HTML|XML" 
    localUrl = "yes|no" 
    marginBottom = "number" 
    marginLeft = "number" 
    marginRight = "number" 
    marginTop = "number" 
    mimeType = "text/plain|application/xml|image/jpeg|image/png|image/bmp|image/gif" 
    name = "output variable name" 
    openpassword = "password to open protected documents" 
    orientation = "portrait|landscape" 
    overwrite = "yes|no" 
    ownerPassword = "password" 
    pageHeight = "page height in inches" 
    pageType = "page type" 
    pageWidth = "page width in inches" 
    pdfa = "yes|no" 
    permissions = "permission list" 
    permissionspassword = "password to access restricted permissions" 
    proxyHost = "IP address or server name for proxy host" 
    proxyPassword = "password for the proxy host" 
    proxyPort = "port of the proxy host" 
    proxyUser = "user name for the proxy host" 
    saveAsName = "PDF filename" 
    scale = "percentage less than 100" 
    src = "URL|pathname relative to web root" 
    srcfile = "absolute pathname to a file" 
    tagged = "yes|no" 
    unit = "in|cm" 
    userAgent = "HTTP user agent identifier" 
    userPassword = "password"> 
        HTML and CFML code 
</cfdocument>
Note: You can specify this tag’s attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag’s attribute names as structure keys.

Attributes

AttributeDescriptionRequiredDefault
authPasswordPassword sent to the target URL for Basic Authentication. Combined with username to form a base64 encoded string that is passed in the Authenticate header. Does not provide support for Integrated Windows, NTLM, or Kerebos authentication.Optional
authUserUser name sent to the target URL for Basic Authentication. Combined with password to form a base64 encoded string that is passed in the Authenticate header. Does not provide support for Integrated Windows, NTLM, or Kerebos authentication.Optional
backgroundVisibleSpecifies whether the background prints when the user prints the document: yes: includes the background when printing. no: does not includes the background when printing.Optionalno
bookmarkSpecifies whether bookmarks are created in the document: yes: creates bookmarks. no: does not create bookmarks.Optionalno
encryption(format="PDF" only) Specifies whether the output is encrypted: 128-bit 40-bit noneOptionalnone
filenamePathname of a file to contain the PDF or FlashPaper output. If you omit the filename attribute, ColdFusion displays the output in the browser.Optional
fontEmbedSpecifies whether ColdFusion embeds fonts in the output: yes: embeds fonts. no: does not embed fonts. selective: embed sall fonts except Java fonts and core fonts.Optionalyes
formatReport format: PDF FlashPaperRequired
formfieldsThis attribute is available only if you have integrated OpenOffice with ColdFusion. A Boolean value that specifies if form fields are exported as widgets or only their fixed print representation is exported.Optionalyes
formstypeThis attribute is available only if you have integrated OpenOffice with ColdFusion. Specifies the submitted format of a PDF form. It can be one of the following values: FDF PDF HTML XMLOptionalFDF
localUrlSpecifies whether to retrieve image files directly from the local drive: yes: ColdFusion retrieves image files directly from the local drive rather than by using HTTP, HTTPS, or proxy. no: ColdFusion uses HTTP, HTTPS, or proxy to retrieve image files even if the files are stored locally. For more information, see the “Using an image file URL” section.Optionalno
marginBottomBottom margin in inches (default) or centimeters. To specify the bottom margin in centimeters, include the unit=cm attribute.Optional
marginLeftLeft margin in inches (default) or centimeters. To specify the left margin in centimeters, include the unit=cm attribute.Optional
marginRightRight margin in inches (default) or centimeters. To specify the right margin in centimeters, include the unit=cm attribute.Optional
marginTopTop margin in inches (default) or centimeters. To specify the top margin in centimeters, include the unit=cm attribute.Optional
mimeTypeMIME type of the source document. Supported MIME types are: text/html text/plain application/xml image/bmp image/jpeg image/png image/gif If you do not specify this attribute explicitly, ColdFusion uses the filename to determine the MIME type.Optionaltext/html
nameName of an existing variable into which the tag stores the PDF or FlashPaper output.Optional
openpasswordThis attribute is available only if you have integrated OpenOffice with ColdFusion. Password required to open a password-protected document.Optional
orientationPage orientation: portrait landscapeOptionalportrait
overwriteSpecifies whether ColdFusion overwrites an existing file. Used in conjunction with the filename attribute.Optionalno
ownerPassword(format="PDF" only) Specifies the owner password.Optional
pageHeightPage height in inches (default) or centimeters. This attribute is only valid if pagetype=custom. To specify page height in centimeters, include the unit=cm attribute.Optional
pageTypePage type into which ColdFusion generates the report: legal: 8.5 inches x 14 inches. letter: 8.5 inches x 11 inches. A4: 8.27 inches x 11.69 inches. A5: 5.81 inches x 8.25 inches. B4: 9.88 inches x 13.88 inches. B5: 7 inches x 9.88 inches. B4-JIS: 10.13 inches x 14.31 inches. B5-JIS: 7.19 inches x 10.13 inches. custom: custom height and width. If you specify custom, also specify the pageHeight and pageWidth attributes, can optionally specify margin attributes and whether the units are inches or centimeters.Optionalletter
pageWidthPage width in inches (default) or centimeters. This attribute is only valid if pageType=custom. To specify page width in centimeters, include the unit=cm attribute.Optional
pdfaThis attribute is available only if you have integrated OpenOffice with ColdFusion. A Boolean value that specifies if you need to create a PDF of type PDF/A-1 (ISO 19005-1:2005) .Optionalno
permissionpasswrdThis attribute is available only if you have integrated OpenOffice with ColdFusion. Password required to access restricted permissions. The restricted permissions are specified using the permissions attribute.Optional
permissions(format="PDF" only) Sets one or more of the following permissions: AllowPrinting AllowModifyContents AllowCopy AllowModifyAnnotations AllowFillIn AllowScreenReaders AllowAssembly AllowDegradedPrinting Separate multiple permissions with commas.Optional
proxyHostHost name or IP address of a proxy server to which to send the request.Optional
proxyPasswordPassword required by the proxy server.Optional
proxyPortThe port to connect to on the proxy server.Optional80
proxyUserUser name to provide to the proxy server.Optional
saveAsName(format="PDF" only) The filename that appears in the SaveAs dialog when a user saves a PDF file written to the browser.Optional
scaleScale factor as a percentage. Use this option to reduce the size of the HTML output so that it fits on that paper. Specify a number less than 100.OptionalCalculated by ColdFusion
srcURL or the relative path to the web root. You cannot specify both the src and srcfile attributes. The file must be in a browser-writable format such as, HTML, HTM, BMP, PNG, and so on.Optional
srcfileAbsolute path of a file that is on the server. You cannot specify both the src and srcfile attributes. The file must be a PPT file, a Word file, or be in a browser-writable format such as, HTML, HTM, BMP, PNG, and so on.Optional
taggedThis attribute is available only if you have integrated OpenOffice with ColdFusion. A Boolean value that determines if the PDF is created using the Tagged PDF tag.Optionalno
unitDefault unit for the pageHeight, pageWidth, and margin attributes: in: inches. cm: centimeters.Optionalin
userAgentText to put in the HTTP User-Agent request header field. Used to identify the request client software.OptionalColdFusion
userPassword(format="PDF" only) Specifies a user password.Optional

Usage

Use the cfdocument tag to render HTML and CFML output into PDF or FlashPaper format. ColdFusion does not return HTML and CFML outside of the <cfdocument></cfdocument> pair.
The cfdocument tag can render HTML that supports the following standards:
HTML 4.01
XML 1.0
DOM Level 1 and 2
CSS1 and CSS2 (For more information, see the “Supported CSS styles” section).
The cfdocument tag does not support the Internet Explorer-specific HTML generated by Microsoft Word.
Use the following syntax in the filename attribute to specify an in-memory file, which is not written to disk. In-memory files speed processing of transient data.
ram:///filepath The filepath can include directories, for example ram:///petStore/tracking/ordersummary.pdf. Create the directories in the path before you specify the file. For more information on using in-memory files, see Optimizing transient files in the Developing ColdFusion Applications.
You can use the src, srcfile, and mimeType attributes to create PDF or FlashPaper output from a specified file or URL. Use the src and srcfile attributes instead of using the cfhttp tag to display the result in the cfdocument tag. When you specify the src or srcfile attributes, do not include any other content inside the cfdocument tag: ColdFusion ignores the additional content.
The PDF or FlashPaper document returned by the cfdocument tag overwrites any previous HTML in the input stream and ignores any HTML after the </cfdocument> tag.
You cannot embed a cfreport tag in a cfdocument tag.
Note: If you notice that the header text is cropped in the cfdocument tag output, increase the value of the marginTop attribute.

Example

Example 1
<!--- This example creates generates a FlashPaper document. ---> 
<cfdocument format="flashpaper"> 
This is a document rendered by the cfdocument tag.</p> 
 
<table width="50%" border="2" cellspacing="2" cellpadding="2"> 
<tr> 
<td><strong>Name</strong></td> 
<td><strong>Role</strong></td> 
</tr> 
<tr> 
<td>Bill</td> 
<td>Lead</td> 
</tr> 
<tr> 
<td>Susan</td> 
<td>Principal Writer</td> 
</tr> 
<tr> 
<td>Adelaide</td> 
<td>Part Time Senior Writer</td> 
</tr> 
<tr> 
<td>Thomas</td> 
<td>Full Time for 6 months</td> 
</tr> 
<tr> 
<td>Michael</td> 
<td>Full Time for 4 months</td> 
</tr> 
</table> 
</cfdocument>
Example 2
<!--- The following example shows how to use the cfdocument scope variables to generate section numbers and page numbers. ---> 
 
<cfdocument format="pdf"> 
<cfdocumentitem type="header" evalatprint="true"> 
    <table width="100%" border="0" cellpadding="0" cellspacing="0"> 
        <tr><td align="right"><cfoutput>#cfdocument.currentsectionpagenumber# of 
            #cfdocument.totalsectionpagecount#</cfoutput></td></tr> 
    </table> 
</cfdocumentitem> 
 
<cfdocumentitem type="footer" evalatprint="true"> 
    <table width="100%" border="0" cellpadding="0" cellspacing="0"> 
        <tr><td align="center"><cfoutput>#cfdocument.currentpagenumber# of 
            #cfdocument.totalpagecount#</cfoutput></td></tr> 
    </table> 
</cfdocumentitem> 
 
<cfdocumentsection> 
    <h1>Section 1</h1> 
    <cfloop from=1 to=50 index="i"> 
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
    </cfloop> 
</cfdocumentsection> 
 
<cfdocumentsection> 
    <h1>Section 2</h1> 
    <cfloop from=1 to=50 index="i"> 
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
    </cfloop> 
</cfdocumentsection> 
 
<cfdocumentsection> 
<h1>Section 3</h1> 
    <cfloop from=1 to=50 index="i"> 
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
    </cfloop> 
</cfdocumentsection> 
</cfdocument>