Enhanced PDF 2.0 in ColdFusion

Adobe ColdFusion (2023 release) introduces a new PDF Engine 2.0.

How to enable it

In ColdFusion Administrator > Data and Services > PDF Service, the option for the new engine is selected by default.

About PDF 2.0

PDF Engine 2.0 is a one-stop shop for converting any HTML to a perfect standard PDF. It supports HTML5, CSS3, and JavaScript. It is typically used for server-side conversion of HTML to PDF, ranging from dynamic data-driven documents (reports, invoices, forms, data sheets) for electronic distribution to complex and high-quality PDFs (catalogs, marketing collateral, technical documentation, journals) for print and electronic publishing.

This new engine will be available on all platforms by default I.e., Windows, Linux, Mac, and Solaris.

Note:
  1. If you want to convert many pdfs, then we recommend that you increase the memory setting in the jetty.lax file to 1024MB using –Xmx1024m.
  2. Changes to the web.xml file- The last four settings mentioned will only be applicable to engine 1.0 only and they will not be applicable to the new engine 2.0. These are the settings:

        maxPDFConversionForService, startScanPort, endScanPort, maxMemoryUsage

HTML5

Converts your HTML5 to PDF documents without additional pre-processing or clean-up. The engine supports all HTML5 elements.

Example

<cfhtmltopdf destination="canvas.pdf" overwrite="yes">
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Filling Color inside a Rectangle on the Canvas</title>
<style>
canvas {
border: 1px solid #000;  
}
</style>
<script>
  window.onload = function() {
    var canvas = document.getElementById("myCanvas");
    var context = canvas.getContext("2d");
    context.rect(50, 50, 200, 100); 
    context.fillStyle = "#FB8B89";
    context.fill();
    context.lineWidth = 5;
    context.strokeStyle = "black";
    context.stroke();
  };
</script>
</head>
<body>
  <canvas id="myCanvas" width="300" height="200"></canvas>
</body>
</html>
</cfhtmltopdf>

Output

CSS3

Use calc, media queries, box-shadow, text-shadow, and filter. Transform, rotate, and scale, elements for converting HTML + CSS to PDF. The engine supports regions, running elements, Grid, and Flexible Box Layout.

Example

<cfhtmltopdf destination="CSS3_Flexbox.pdf" overwrite="yes"> 
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example of Controlling Flow inside Flex Container along Main Axis</title>
<style>
.flex-container {
    width: 80%;
    min-height: 300px;
    margin: 0 auto;
    font-size: 32px;
    display: -webkit-flex;
    -webkit-flex-direction: row-reverse;
    display: flex;
    flex-direction: row-reverse;
    border: 1px solid #666;
}
.flex-container div {
    padding: 10px;
    -webkit-flex: 1; 
    -ms-flex: 1;
    flex: 1; 
}
.item1 {
    background: #e84d51;
}
.item2 {
    background: #7ed636;
}
.item3 {
    background: #2f97ff;
}
</style>
</head>
<body>
<div class="flex-container">
<div class="item1">Item 1</div>
<div class="item2">Item 2</div>
<div class="item3">Item 3</div>
</div>

</body>
</html>
</cfhtmltopdf>

Output

JavaScript

Transfer JavaScript-driven layouts to PDF. There is also support for HTML5 Canvas, HighCharts, and other JavaScript libraries out of the box.

Example

<cfhtmltopdf destination=”js.pdf” overwrite="yes">
    <!DOCTYPE html>
    <html>
       <head>
        <link rel = "stylesheet" href = "http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
        <script src = "http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>   </head>   <body>
        <div id = "map" style = "width: 900px; height: 580px"></div>
        <script>
            // Creating map options
            var mapOptions = {
               center: [17.385044, 78.486671],
               zoom: 10
            }        // Creating a map object
            var map = new L.map('map', mapOptions);        // Creating a Layer object
            var layer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');        // Adding layer to the map
            map.addLayer(layer);
         </script>
       </body>
    </html>
    </cfhtmltopdf>

Output

PDF/A Conformance

PDF 2.0 supports the creation of PDF/A-1a or PDF/A-3a conformant files, as well as other PDF/A subformats.

PDF/A is a family of ISO standards ("ISO 19005") for the long-term archiving of documents. The goal of these standards is to ensure the reproduction of the visual appearance as well as the inclusion of the document's structure. All information necessary for displaying the document, in the same way, every time is embedded in the file. Dependencies on external resources are not permitted. PDF/A-1a and PDF/A-3a also require the output PDF documents to be tagged, providing accessible documents.

PDF2.0 ensures that the requirements are met as far as possible.

The supported PDF/A conformance levels are PDF/A-1a, PDF/A-1b, PDF/A-2a, PDF/A-2b, PDF/A-2u, PDF/A-3a, PDF/A-3b and PDF/A-3u.

Conformance can be added as an attribute to cfhtmltopdf tag as below:

Example

<cfhtmltopdf source="input.html" destination="pdfa3u.pdf" conformance="PDFA3u" overwrite="yes">
</cfhtmltopdf>

Enhanced Headers and Footers

PDF 2.0 supports HTML content in headers and footers.

Previously it was only static text, but now any HTML elements can be used to create beautiful, modern headers and footers.

<cfhtmltopdf> 
    some html content.
    <cfhtmltopdfitem type="header"> 
    <html>
        <table 
            width="100%" 
            style="font-size: 12px; font-family: Tahoma, sans-serif" > 
            <tr> 
                <td valign="top" align="left" width="50%"> 
                    <img border="0" height="88" 
                    src=https://www.google.co.uk/logos/doodles/2022/seasonal-holidays-2022-
    6753651837109831.4-law.gif  /> 
                </td> 
                <td valign="center" align="left" height="50%" width="50%"> 
                    <h1>Header</h1> 
                </td> 
            </tr> 
        </table> 
        <table 
            width="100%" 
            style="border-bottom: 1px; 
                font-size: 10px; 
                font-family: Tahoma, sans-serif; cellspacing=5" >
            <tr> 
                <td valign="middle" align="center" width="10%"> 
                    <strong>Sl No.</strong> 
                </td> 
                <td valign="middle" align="left" width="36%"> 
                    <strong>Column1</strong> 
                </td> 
                <td valign="middle" align="right" width="10%"> 
                    <strong>Column2</strong> 
                </td> 
                <td valign="middle" align="right" width="12%"> 
                    <strong>Column3</strong> 
                </td> 
            </tr> 
        </table> 
    </html>
    </cfhtmltopdfitem> 
    <cfhtmltopdfitem type="pagebreak">
    </cfhtmltopdfitem>
    <cfhtmltopdfitem type="footer">
    <p>footer</p>
    </cfhtmltopdfitem> 
</cfhtmltopdf>  

Output

Get help faster and easier

New user?