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

CFDocument Intelligently Reuses Repeated Image Objects In Lucee CFML 5.3.4.80
1.30 GEEK