Details:
CFDOCUMENT tag in ColdFusion can be used to create PDF output from a text block containing CFML or HTML. We use images and styles to be embed into the PDF through HTML. Sometimes while trying to embed images and styles to the PDF, we may face issues like, “Invisible images”, “Styles not reflecting”, etc., if the website is hosted in SSL environment.
Further Details:
SSL affects style and image embedding. If we are using SSL certificate and it is not trusted by the JVM, then request will fail. In default case JVM trusts some renowned names for SSL like VeriSign, Thawte etc. And if we are creating PDF with image and styles and the server is behind a firewall, we cannot resolve the IP/URL those are internally referred.
Example:
Normally we use the following syntax to use an image in HTML page which has the relative path to an image.
<img src=”../images/myImage.jpg” style=”width:40; height:40” />
|
Solution:
If CFDOCUMENT has external CSS included (not inline styles), then CFDOCUMENT finds those external resources to use, it does not include the resources like in CFINCLUDE. CFDOCUMENT acts as a browser and uses HTTP to get those resources (CSS and images). By this the server resolves the IP or URL that we have used to refer resources.
So if the files are local, a better and simpler solution is, we can use “file:” protocol with 3 leading slashes (“file:///”) in the image SRC or CSS source. It also speeds up the CFDOCUMENT call.
|
<IMG SRC="file:///c:\mywebsite\images\ myImage.jpg" style=”width:40; height:40” />
OR
<CFOUTPUT><IMG SRC="file:///#ExpandPath(/images/ myImage.jpg)#" /></CFOUTPUT> <link HREF="file:///c:\mywebsite\styles\myStyle.css" rel="stylesheet" type="text/css" />