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 string
Default: none

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

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

Values:
  • 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.
Values:
  • AllowPrinting
  • AllowModifyContents
  • AllowCopy
  • AllowModifyAnnotations
  • AllowFillIn
  • AllowScreenReaders
  • AllowAssembly
  • AllowDegradedPrinting
  • AllowSecure
  • All
  • None

pageType string
Default: Letter

Values:
  • 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:
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

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>

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>

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>

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