cfdocument

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

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

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

Attribute Reference for the cfdocument tag

format

Required: Yes
Specifies the report format. Values:
  • PDF
  • FlashPaper

filename

Required: No
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

Required: No
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

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

name

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

pagetype

Required: No
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

Required: No
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

Required: No
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

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

margintop

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

marginbottom

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

marginleft

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

marginright

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

unit

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

encryption

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

ownerpassword

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

userpassword

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

permissions

Required: No
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

Required: No
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

Required: No
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

Required: No
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

Required: No
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

Required: No
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

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

localurl

Required: No
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

Required: No
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

Required: No
Password required by the proxy server.

proxyuser

Required: No
User name to provide to the proxy server.

saveasname

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

src

Required: No
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

Required: No
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

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

proxyhost

Required: No
IP address or server name for proxy host.

proxyport

Required: No
port of the proxy host.

tagged

Required: No
Default: NO
Determines if PDF are created by using special tags also known as Tagged PDF

pdfa

Required: No
Default: NO
Creates a PDF of type PDF/A-1 (ISO 19005-1:2005)

formFields

Required: No
Default: YES
Specifies whether form fields are exported as widgets or only their fixed print representation is exported.

formsType

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

permissionsPassword

Required: No
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

Required: No
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