Regression: Local images no longer render in PDF in Lucee 5.3+

Description

This code produces a PDF with an image that pulls from a local file path and works on Lucee 5.2

<cfoutput> <cfdocument format="PDF" filename="testout.pdf" overwrite="true" localurl="true"> Here is an image: <img src="file:///D:\path\to my\image.jpg"> </cfdocument> done </cfoutput>

However, the same code produces a PDF with no image on Lucee 5.3+

I've narrowed down to the fact that Lucee 5.3's PDF engine requires the file paths to

  • Be URL encoded (sort of as URLEncodedFormat() and encodeForURL() both cause issues)

  • use only forward slashes, even on Windows.

If I run all my local file paths through this code, it seems to work:

function pathToURL( required string path ) { return createOBject( 'java', 'java.io.File' ).init( path ) .toURI() .toURL() .toString(); }

That would turn the path above (that worked in Lucee 5.2) into this:

file:/D:/path/to%20my/image.jpg

Environment

None

Activity

Brad Wood 24 August 2020 at 16:34

Thanks Micha!

michael 22 August 2020 at 18:43

fair concern. I will use a Uri path in case of a already local file. that is a simple change. but i will still download external files, the http FS already can use the global proxy.

BTW better use HTTPUtil.toURL(…) instead of new URL() it will give you better results.

Brad Wood 21 August 2020 at 15:50

Looking at your commit, I have some concerns about your implementation. Instead of using my fix I provided in the ticket and confirmed, it appears you're reading the image to base64 and including it inline in the PDF. I stronglyk recommend against this. I tested this and while it works well for small PDFs containing few images, it performs very poorly for large PDFs containing a lot of images.

Can you please confirm that the PDF extension will not be trying to convert all images to base64 and in-lining them. That is not a good solution. The best solution is the one I showed in the ticket description.

Fixed

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Created 4 November 2019 at 18:47
Updated 27 August 2020 at 15:13
Resolved 27 August 2020 at 15:13