cfhtmltopdf

Creates PDFs from HTML using a WebKit based rendering engine.

 <cfhtmltopdf>html</cfhtmltopdf>

 cfhtmltopdf() { writeOutput(html); };

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

Attribute Reference for the cfhtmltopdf tag

encryption

Required: No
Default: none
Values:
  • AES_128
  • RC4_40
  • RC4_128
  • RC4_128M
  • none

destination

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

marginBottom

Required: No
Bottom margin in inches or cm based on unit attribute

marginTop

Required: No
Top margin in inches or cm based on unit attribute

marginLeft

Required: No
Left margin in inches or cm based on unit attribute

marginRight

Required: No
Right margin in inches or cm based on unit attribute

name

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

orientation

Required: No
Default: portrait
Values:
  • portrait
  • landscape

overwrite

Required: No
Default: no
Specifies whether ColdFusion overwrites an existing file. Used in conjunction with the destination attribute.

ownerPassword

Required: No
Specifies the owner password. Cannot be same as userPassword.

userPassword

Required: No
Specifies a user password. Cannot be same as ownerPassword.

permissions

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

pageType

Required: No
Default: Letter
Values:
  • legal
  • letter
  • A4
  • A5
  • B4
  • B5
  • B4-JIS
  • B5-JIS
  • custom

pageWidth

Required: No
Only valid if pagetype=custom. based on unit attribute

pageHeight

Required: No
Only valid if pagetype=custom. based on unit attribute

saveAsName

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

unit

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

Compatibility

ColdFusion:

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

Links more information about cfhtmltopdf

Examples sample code using the cfhtmltopdf tag


Basic Usage

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.

<cfhtmltopdf>
  <h1>Hello World</h1>
</cfhtmltopdf>

External Source

Use the source attribute to specify an external url.

<cfhtmltopdf
 destination="usage_example.pdf" overwrite="yes"
 source="http://www.google.com/"
 unit="in" pageheight="8" pagewidth="4"
 pagetype="custom">
</cfhtmltopdf>

Set Margins

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


<cfhtmltopdf destination="usage_example2.pdf"
 source="http://www.google.com" overwrite="true" 
 orientation="portrait" pagetype="A4" margintop="1" marginbottom="1" 
 marginleft="1" marginright="1">
</cfhtmltopdf>

Protect PDF

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


<cfhtmltopdf 
 source="http://www.google.com"
 ownerpassword="owner" userpassword="user"
 encryption="RC4_128" permissions="AllowPrinting,AllowCopy">
</cfhtmltopdf>

Fork me on GitHub