+ Start a Discussion
Edward GeeEdward Gee 

Recommendation for partners regarding images in PDF view of Visualforce page

We are developing/deploying solutions leveraging Visualforce pages.  Our pages contain image references to external URL sites.  When the page is rendered online, it works as expected.  However, when I apply the renderAs="pdf" attribute to our pages, the images appear as broken image links in the pdf.  I have read somewhere that we should be using static resources.  Granted that does work but it becomes a maintanence nightmare for partners when deploying solutions to many customer orgs.  Instead of maintaining the resources on our own server for many customer orgs, we would have to touch each customer org to deploy patches or upgrades.

We would like to receive some advice from Salesforce regarding this approach and discuss if this may even be a bug.

Code sample:
Code:
<!-- All of these images render fine without the renderAs="pdf" attribute -->
<apex:page renderAs="pdf">
  <h1>Congratulations</h1>
  This is your new Page: ImageTest
  <p/>
  <!-- Doesn't render in pdf -->
  <apex:image style="border:thin solid black" value="http://www.google.com/intl/en_ALL/images/logo.gif"></apex:image>
  <p/>
  <!-- Oddly enough renders in pdf -->
  <apex:image style="border:thin solid black" value="http://www.salesforce.com/common/assets/images/logo_hm_summ_nosoftware.gif"></apex:image>
  <p/>
  <!-- Renders in pdf (obviously if you have the resource "vheader" defined for your org -->
  <apex:image style="border:thin solid black" url="{!$Resource.vheader}"></apex:image>
  <p/>
</apex:page>

 

dchasmandchasman
Not a bug - this is working as designed and is a result of our server side policies around requests to external sites and is a security enforcement mechanism. We have adding support for leveraging the whitelist for external callouts to allow selective and controlled access to external content. I do not have a ETA for this enhancement at this time.

I verified (you should be able to create a page with the markup below in your own org and have it render as PDF correctly) that you can leverage our new Sites feature to publish a publicly accessible static resource to work around this limitation. Basically this works because accessing a public static resource does not require leaving the "cloud" as far as the salesforce servers are concerned. Just create a site with anonymous access and host your static resources there. You then access this shared resource like this:

Code:
<apex:page renderAs="pdf">
<apex:image value="http://dougchasman-developer-edition.na4.force.com/resource/Dutchco__exampleImage"/>
</apex:page>

 
Note that I had to include the Dutchco namespace prefix in my case because the org hosting the dougchasman site is namespaced - your situation may be different.


Message Edited by dchasman on 01-02-2009 10:37 AM
Edward GeeEdward Gee
Thanks Doug for the reply.  As discussed, the solutions described in this thread works well for static resources.  Unfortunately, there are some resources we dynamically generate from our servers such as captured images that are stored encoded in a text area long field.

We would be interested in a solution that leverages the whitelist for external callouts.  For now, it seems we will have to solve this one customer requirement outside of the Visualforce framework.
dchasmandchasman
I am confused - is the encoded image data store in a salesforce long text area or something like an LTA in your own storage mechism external to salesforce? If it is store in salesforce what is the codec you're using? If it not in salesforce would it be acceptable to use the sfdc api to push the images into salesforce (either as a batch operation or perhaps wired into your existing storage mechanism if external)?


Message Edited by dchasman on 01-04-2009 03:38 PM
Edward GeeEdward Gee
We base64 encode a small png image into a Salesforce long text area field.  We store all customer data in Salesforce.
dchasmandchasman
An update on this: in Spring '09 release I have added support for PDF generation to be able to access external content using the Remote Sites configuration already in place for apex code callouts and the ajax toolkit proxy!
Edward GeeEdward Gee
Great!  We look forward to checking out the new addition in the Spring '09 release.