CFDocument Intelligently Reuses Repeated Image Objects In Lucee CFML

CFDocument Intelligently Reuses Repeated Image Objects In Lucee CFML

Ben Nadel looks at how repeated Image objects affect file-size in the CFDocument tag in Lucee CFML 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

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" />


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

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


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

                        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" )#" />

                <cfdocumentitem type="pagebreak" />




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

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


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.