Creates PDFs from HTML using a WebKit based rendering engine.


 cfhtmltopdf() { writeOutput(html); };

This tag requires Adobe ColdFusion 11 and up.  Not supported on Lucee, etc.

Attribute Reference

encryption string
Default: none

  • AES_128
  • RC4_40
  • RC4_128
  • RC4_128M
  • none

source string

A URL of the source HTML document to use instead of providing content directly.

destination string

Pathname of a file to contain the PDF output. If you omit the destination attribute, ColdFusion displays the output in the browser.

marginBottom numeric

Bottom margin in inches or cm based on unit attribute

marginTop numeric

Top margin in inches or cm based on unit attribute

marginLeft numeric

Left margin in inches or cm based on unit attribute

marginRight numeric

Right margin in inches or cm based on unit attribute

name variableName

Name of an existing variable into which the tag stores the PDF.

orientation string
Default: portrait

  • portrait
  • landscape

overwrite string
Default: no

Specifies whether ColdFusion overwrites an existing file. Used in conjunction with the destination attribute.

ownerPassword string

Specifies the owner password. Cannot be same as userPassword.

userPassword string

Specifies a user password. Cannot be same as ownerPassword.

permissions string

Separate multiple permissions with commas.
  • AllowPrinting
  • AllowModifyContents
  • AllowCopy
  • AllowModifyAnnotations
  • AllowFillIn
  • AllowScreenReaders
  • AllowAssembly
  • AllowDegradedPrinting
  • AllowSecure
  • All
  • None

pageType string
Default: letter

Provide a type with standard dimensions or indicate custom to define your own
  • legal
  • letter
  • A4
  • A5
  • B4
  • B5
  • B4-JIS
  • B5-JIS
  • custom

pageWidth numeric

Only valid if pagetype=custom. based on unit attribute

pageHeight numeric

Only valid if pagetype=custom. based on unit attribute

saveAsName string

The filename that appears in the SaveAs dialog when a user saves a PDF file written to the browser.

unit string
Default: in

Default unit for the pageHeight, pageWidth, and margin attributes:
  • in
  • cm

language string
Default: English

CF 2016+ Document language



Version 11+ The rendering engine only runs on Windows or Linux. You can still run this tag on a Mac, but it must connect to a remote rendering engine running on Windows or Linux. Rendering engines are configured in the ColdFusion administrator.

Links more information about cfhtmltopdf

Sample code using the cfhtmltopdf tag

Put HTML inside the tags to render it as a PDF. When the destination attribute is omitted the pdf is sent back to the browser.

  <h1>Hello World</h1>

Use the source attribute to specify an external url.

 destination="usage_example.pdf" overwrite="yes"
 unit="in" pageheight="8" pagewidth="4"

Uses the margintop, marginbottom, marginleft, marginright to set the page margins

<cfhtmltopdf destination="usage_example2.pdf"
 source="" overwrite="true" 
 orientation="portrait" pagetype="A4" margintop="1" marginbottom="1" 
 marginleft="1" marginright="1">

Uses the ownerpassword, encryption, and permissions attributes to produce a password encrypted pdf.

 ownerpassword="owner" userpassword="user"
 encryption="RC4_128" permissions="AllowPrinting,AllowCopy">

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub