May 17, 2023
ColdFusion 2023 – HTML to PDF
Comments
(0)
May 17, 2023
ColdFusion 2023 – HTML to PDF
ColdFusion developer for 20+ years, professional experience in 10 other languages & frameworks. Artist, nerd, Jeep enthusiast.
Newbie 35 posts
Followers: 26 people
(0)

The HTML to PDF conversion functionality allows developers to convert HTML files, strings, or URLs into PDF documents. The feature proves beneficial when you need to provide website content in a portable, easily shareable format. Reports, invoices, and other documentation often need to be generated as PDFs from HTML content. Adobe ColdFusion makes this process straightforward and efficient.

When the <cfhtmltopdf> tag first came out, it changed the game in terms of outputting PDF documents from your code. But as time passed, the engine used grew old and out of date with modern web standards, image types and other embedded objects. With CF2023, we are introducing a fully uprated new “2.0” PDF generation engine, now capable of supporting all of your document creation workflows, modern CSS and HTML5 structures, images, video and audio embedding needs.

What kinds of things does the new engine support?

  • SVG
  • Embedded video
  • Embedded Audio
  • Flexbox layouts
  • CSS Grid layouts
  • PDF/A conformance and support
  • Rendering canvas elements
  • Dynamic rendering via JavaScript (for example, from charting libraries)

The takeaway here is that you will no longer be required to use CFDocument to generate PDF documents, you can simply create the layout and template you want and use CFHTMLtoPDF to save a PDF file with that content, in a pixel-perfect format.

The best part is that if you are already using CFHTMLTOPDF, it will just work right out of the box. For this release, we have not added any new attributes. You can still encrypt the PDF, add margins, set passwords, etc. The biggest changes come from the ability of the engine to interpret and render the objects you need to display, in perfect layout, every time.

Let’s take a look at an example of using one of the new features in your website: rendering SVG images. For those unfamiliar with this format, SVG is a vector-based image format usable on the web. This means that it can scale to whatever size you want or need without any loss in image quality or pixelation.

Go to https://github.com/MarkRTakata/CF2023/tree/main/html2pdf.

Download the files, and take a look at Sample2.cfm and testpdf-svgsource.cfm (the latter of which obviously does not have to be in cfm format of course).

Sample2.cfm takes the source file, which contains an SVG format image (in this case, a race car) and renders a PDF, then pushes that file into the browser. You’ll note it can scale to any size you want, as vector format images are good at that. In the previous engine, you’d get a blank page instead. (You can test this by going into the CF Administrator and going to Data & Services / PDF Service, changing the engine from 2.0 (the new default) to 1.0 and restarting ColdFusion. Make sure you reset that after you’re done to get all the great new features of the new engine though!

For more documentation on the CFHTMLtoPDF tag and functionality, please visit https://helpx.adobe.com/coldfusion/using/coldfusion-enhanced-pdf.html

 

 

0 Comments
Add Comment