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.

cfhtmltopdf Attribute Reference

encryption
Default: none

Values:
  • AES_128
  • RC4_40
  • RC4_128
  • RC4_128M
  • none

destination

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

marginBottom

Bottom margin in inches or cm based on unit attribute

marginTop

Top margin in inches or cm based on unit attribute

marginLeft

Left margin in inches or cm based on unit attribute

marginRight

Right margin in inches or cm based on unit attribute

name

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

orientation
Default: portrait

Values:
  • portrait
  • landscape

overwrite
Default: no

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

ownerPassword

Specifies the owner password. Cannot be same as userPassword.

userPassword

Specifies a user password. Cannot be same as ownerPassword.

permissions

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

pageType
Default: Letter

Values:
  • legal
  • letter
  • A4
  • A5
  • B4
  • B5
  • B4-JIS
  • B5-JIS
  • custom

pageWidth

Only valid if pagetype=custom. based on unit attribute

pageHeight

Only valid if pagetype=custom. based on unit attribute

saveAsName

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

unit
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