CFDocument Intelligently Reuses Repeated Image Objects In Lucee CFML 5.3.4.80

CFDocument Intelligently Reuses Repeated Image Objects In Lucee CFML 5.3.4.80

Ben Nadel looks at how repeated Image objects affect file-size in the CFDocument tag in Lucee CFML 5.3.4.80. It seems that an image is embedded once and then intelligently reused as needed. This should guide how different versions of an image are implemented within a single PDF document.

The other day, I experimented with saving InVision prototypes as interactive PDFs in Lucee CFML. And, while very few people will have an interest in such a technique, it's gotten me thinking a lot about how I might use PDFs more effectively. One thing I started to wonder about is how CFDocument handles repeated Image URLs. The answer to this would certainly influence how I would implement different types of PDF content: whether I crop images in a pre-processing step, generating unique image URLs per cropping; or, whether I should just use overflow:hidden in order to simulate cropping on a repeated image URL. To explore this, I created a simple demo in which I can dynamically repeat an image in a CFDocument tag using Lucee CFML 5.3.4.80.

This demo is super simple. All I'm doing is passing in a URL parameter, pageCount, and then using CFLoop to generate N-number of pages all with the same img tag and src attribute:

<!--- We can use the URL to drive the number of pages generated in the PDF. --->
<cfparam name="url.pageCount" type="numeric" default="1" />

<cfdocument
    format="pdf"
    filename="./images.pdf"
    overwrite="true"
    localurl="true"
    orientation="portrait"
    pagetype="a4"
    margintop="0.5"
    marginright="0.5"
    marginbottom="0.5"
    marginleft="0.5">

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="utf-8" />
        <style type="text/css">

            p img {
                border: 3px solid #ff3366 ;
                width: 600px ;
            }

        </style>
    </head>
    <body>

        <cfoutput>
            <cfloop index="i" from="1" to="#url.pageCount#" step="1">

                <p>
                    <!---
                        This IMAGE file is going to be used on N-number of pages. We can
                        look at the size (bytes on disk) of the generated file to see if
                        the repeated image is "reused" intelligently.
                    --->
                    <img src="file:///#expandPath( "./goose-duck.jpg" )#" />
                </p>

                <cfdocumentitem type="pagebreak" />

            </cfloop>
        </cfoutput>

    </body>
    </html>

</cfdocument>

<!--- Now that the file has been generated, let's look at the file-size. --->
<cfoutput>

    Page Count: #url.pageCount#
    <br />
    File Size: #numberFormat( getFileInfo( "./images.pdf" ).size )#

</cfoutput>

coldfusion artificial intelligence

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

AI Innovations in Artificial Intelligence

Innovations in Artificial Intelligence - Various sectors in which AI is remarkably used & has brought changes in humanity - Education, Healthcare,automobile

Bursting the top 7 common Myths about Artificial Intelligence by Rebecca Harrison

Artificial Intelligence has been the go-to technology for companies and enterprises in recent years. The adoption of AI by enterprises all around the world has grown by 270% in the last four years a...

10 Most Amazing Artificial Intelligence Milestones To Know

Top 10 Artificial Intelligence Milestones to learn AI evolution - Origin,ELIZA,XCON,Statistics Introduction, Chess & jeopardy winner,autonomous vehicles

Top 10 Artificial Intelligence (AI) Interview Questions & Answers

In this Artificial Intelligence Interview Questions blog, you will understand the most frequently asked AI questions and their solutions.

Implement Artificial Intelligence using Artificial Intelligence

Implement Artificial Intelligence using Artificial Intelligence. Artificial Intelligence (AI) requires everybody’s interest and commitment.