Skip to main content
Charlie Arehart
Community Expert
Community Expert
May 2, 2018
Question

Has anyone found a way to support the equivalent of localurl processing CFHTMLtoPDF?

  • May 2, 2018
  • 1 reply
  • 555 views

Some readers may know that CFDOCUMENT has long had a default behavior that if you had an img src (or similar html tag) that pointed to a local file, CF would under the covers turn that into an HTTP call to get the image, which could cause performance or even functionality problems.

And CF8 added a new optional attribute to change that behavior: LocalURL.  (See my blog post from 2011 for more on that: http://www.carehart.org/blog/client/index.cfm/2011/11/19/perf_fix_via_cfdocument_localurl_attribute.)

Sadly, it seems that the new CFHTMLtoPDF (added in CF11) works the same way (I've confirmed by viewing web server logs showing it creating URLs to get images via the web server), and yet it does NOT offer that LocalURL attribute to change that behavior.

Has anyone else encountered or solved this?  I have done a lot of searching about it, to no avail.

I did find that the underlying WKHTML kit does itself offer a --enable-local-file-access option, but it's only for use with the WKHTMLtoPDF that it uses, and upon which CFHTMLtoPDF is based (https://wkhtmltopdf.org/usage/wkhtmltopdf.txt). But I cannot see any way to pass in such an argument to CFHTMLtoPDF.

    This topic has been closed for replies.

    1 reply

    pete_freitag
    Participating Frequently
    May 3, 2018

    Hi Charlie

    You can use a data URI - that is a base64 encoded string representation using the data: scheme in the src attribute of the img tag.

    Here's a code example:

    <cfhtmltopdf>

      <h1>Hello World</h1>

      <cfoutput><img src="data:image/png;base64,#toBase64(fileReadBinary(ExpandPath("./foundeo.png")))#"></cfoutput>

    </cfhtmltopdf>