cfdocument

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

 <cfdocument format="PDF">html</cfdocument>

 cfDocument(format="PDF") { writeOutput(html); };

cfdocument Attribute Reference

format
Required

Specifies the report format. Values:
  • PDF
  • FlashPaper

filename

Specifies the fully qualified path name of a file to
contain the PDF or FlashPaper output. If you omit the
filename attribute, ColdFusion MX streams output to
the browser.

localurl
Default: NO

Specifies 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.

overwrite
Default: NO

Specifies whether ColdFusion MX overwrites an
existing file. Used in conjunction with filename.
Default is: false

name

Specifies the name of an existing variable into which
the tag stores the PDF or FlashPaper output.

pagetype
Default: A4

Specifies the page size 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
- B5: 9.81 inches x 13.88 inches
- Custom: Custom height and width.
If you specify custom, you must also specify the pageheight
and pagewidth attributes, can optionally specify margin
attributes, and can optionally specify whether the units
are inches or centimeters. Values:
  • legal
  • letter
  • A4
  • A5
  • B5
  • custom

pageheight

Specifies the page 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.

pagewidth

Specifies the page 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.

orientation
Default: portrait

Specifies the page orientation. Specify either of the
following:
- portrait (default)
- landscape Values:
  • portrait
  • landscape

margintop

Specifies the top margin in inches (default) or
centimeters. To specify top margin in centimeters,
include the unit=cm attribute.

marginbottom

Specifies the bottom margin in inches (default) or
centimeters. To specify bottom margin in
centimeters, include the unit=cm attribute.

marginleft

Specifies the left margin in inches (default) or
centimeters. To specify left margin in centimeters,
include the unit=cm attribute.

marginright

Specifies the right margin in inches (default) or
centimeters. To specify right margin in centimeters,
include the unit=cm attribute.

unit
Default: in

Specifies the default unit (inches or centimeters) for
pageheight, pagewidth, and margin attributes. Values:
  • in
  • cm

encryption
Default: none

Specifies whether the output is encrypted (format="PDF" only).
Default is: none Values:
  • 128-bit
  • 40-bit
  • none

ownerpassword

Specifies an owner password (format="PDF" only).

userpassword

Specifies a user password (format="PDF" only).

permissions

Specifies one or more permissions (format="PDF" only).
Separate multiple permissions with a comma. Values:
  • AllowPrinting,AllowCopy,AllowScreenReaders
  • AllowPrinting
  • AllowModifyContents
  • AllowCopy
  • AllowModifyAnnotations
  • AllowFillIn
  • AllowScreenReaders
  • AllowAssembly
  • AllowDegradedPrinting
  • AllowPrinting,AllowModifyContents,AllowCopy,AllowModifyAnnotations,AllowFillIn,AllowScreenReaders,AllowAssembly,AllowDegradedPrinting

fontembed
Default: YES

Specifies whether ColdFusion embeds fonts in the output.
Specify one of the following:
- true: Embed fonts
- false: Do not embed fonts.
Selective: Embed all fonts except Java fonts and core fonts.

backgroundvisible
Default: NO

Specifies whether the background prints when the
user prints the document:
- yes: include the background when printing.
- no: do not include the background when printing.

scale

Specifies a scale 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. Values:
  • 100
  • 90
  • 80
  • 70
  • 60
  • 50
  • 40
  • 30
  • 20
  • 10

authpassword

Password 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.

authuser

User 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.

bookmark
Default: NO

Specifies whether bookmarks are created in the document:
* yes: creates bookmarks.
* no: does not create bookmarks.

localurl
Default: NO

Specifies 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.

mimetype
Default: text/html

MIME type of the source document Values:
  • text/html
  • text/plain
  • application/xml
  • image/bmp
  • image/jpeg
  • image/png
  • image/gif

proxypassword

Password required by the proxy server.

proxyuser

User name to provide to the proxy server.

saveasname

(format="PDF" only) The filename that appears in the SaveAs dialog when a user saves a PDF file written to the browser.

src

URL 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.

srcfile

Absolute path of a file that is on the server. 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.

useragent

Text to put in the HTTP User-Agent request header field. Used to identify the request client software.

proxyhost

IP address or server name for proxy host.

proxyport

port of the proxy host.

tagged
Default: NO

Determines if PDF are created by using special tags also known as Tagged PDF

pdfa
Default: NO

Creates a PDF of type PDF/A-1 (ISO 19005-1:2005)

formFields
Default: YES

Specifies whether form fields are exported as widgets or only their fixed print representation is exported.

formsType
Default: FDF

Specifies the submitted format of a PDF form. Values:
  • FDF
  • PDF
  • HTML
  • XML

permissionsPassword

This is the password that allows the user to access some permissions restricted if some permissions need to be restricted. The permissions are defined in "permissions" attribute

openPassword

If the source document is protected specify using this attribute.

Examples sample code using the cfdocument tag


Dynamic PDF Served to Browser

PDF is sent back to the browser instead of saving to a file. The cfheader tag is used to suggest a file name to the browser. The cfcontent tag is used to set the Content-Type response header (that could also be done using cfheader) which tells the browser that it is a PDF file.

<cfcontent type="application/pdf">
<cfheader name="Content-Disposition" value="attachment;filename=example.pdf">
<cfdocument format="pdf">
    <h1>Hello ColdFusion</h1>
    <p>This is <strong>PDF</strong> example document.</p>
    <p>Genereated at: <cfoutput>#TimeFormat(Now())# on #DateFormat(Now())#</cfoutput></p>
</cfdocument>

Fork me on GitHub