function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

problem with rendering PDFs with images

We are having two related issues with using images in our VF pages for our products that we want to render to PDF (we are running in a Sandbox with Summer '08):
1) when we include an image file from an external server , the page will not render at all and gives an error 500.  No PDF is generated at all.    We have tried bringing the image in using both a normal <img> tag as well as the <apex:image >  tags. We have tried being in and out of developer mode, and have tried https and http URLs to the external server that is hosting the image.  The image does show in a browser window when we remove the 'renderAs=PDF'.  We have tried images of various sizes from multiple external servers and the results are always the same - will show in browser window, will not even render the pdf file.
2)   We also have an image at the top of the page which is a Static resource in SF.  this image is essentially our logo header.  When we choose render as pdf, (and remove any external image links), the PDF will be generated however the logo file does not appear.  Again, it shows if we remove the renderAs PDF.  As soon as we try to render as PDF, the image disappears.
Any ideas?  is there any more information that I can provide??
We do not support references to external images (improvements in error handling is in the works) because outbound traffic from our servers is highly controlled for security reasons. External images work in the browser because it is the browser which is running outside of the data center making the request for the resource.

However, the static resource case you describe in #2 should work. What type of file are you using for your logo file (e.g. jpeg, gif, etc)? Can post the part of your page that contains the image reference?
Hi Doug - thanks for the response.

I understand your answer regarding the external images. This is a bummer for us as we do not and most likely will not store the images for  our entire product catalog in Salesforce.  Is there any plan to allow these in the future?   We were rendering straight to PDF since this document is meant for printing, and when we print from the browser window we get the header and footer that the browser slaps on the the output which is no good.

Regarding the static resource Logo (case #2) - the file is a jpg.  Below is the page that we are using to test both of these cases.  As I mentioned, we have tried using normal <img> tags as well as the <apex:image>  tag.  (what is the best practice?)

<apex:page showHeader="false" standardController="Product2">
<link href="{!$Resource.jewelryCSS}" rel="stylesheet" type="text/css" media="all" />

<div id="print" align="center">
<apex:image value="{!$Resource.levlogo}" />
<br />
<apex:image value="" />
<div id="number"> {!product2.ProductCode} </div>
<div id="description"> {!product2.Description} </div>

THANK YOU for your help!

Message Edited by gireeshz on 06-04-2008 08:10 AM
I don't think there is any plan to allow inclusion of external resources in the pdf as it has some security implications like Doug said.

Without The external image, my page worked fine using your markup, so not sure why its not working for you. Can you try following markup in you org and see what happens?

<apex:page showHeader="false" standardController="Product2" renderAs="pdf">
<apex:image value="{!$Resource.IMAGE_FILE}" />

Also its better to use VF tags to include images, css etc. For example, to include css, you should be using stylesheet tag.

Thanks for the info ES.

You sample worked.  Mysteriously, our original page is working now as well.  Wish i had a solid answer for you.  

I hear you on the security issues - maybe we can find some other way of getting a good print from the browser window.

thanks to all..
Hi Doug,

may we run into the same issue, but let me explain. We build a visualforce page, where we would like to show grafical information in different charts. For the charts we use the google chart api. Now nearly finished, we see if we hava a VFP rendered as html it does work, but if we rendered it as pdf, then the area keeps blank. We could not show the charts in the pdf.

Any idea what is the reason for that?
Yes, there are actually a couple of issues here. The PDF generation happens in the server farm and currently (and not likely to change) the firewall is configured to not allow outbound connections such as this which makes it impossible for the PDF generation engine to even talk to google. Second, pages that you want to render as PDF cannot rely on javascript to generate their content - the content generated from running the VF page must be HTML only, any javascript/DHTML will basically be ignored (this HTML is not being evaluated by a browser remember).

Hi Doug,

We are creating a PDF document using Visual Force Page and the document has a logo ( a png or gif image file on header). Currently the image file is a static resource and using merge field the VF page is able to display it correctly. When we do the packaging the resource is also packaged and is getting installed without any issues.


Now we want to change the logo at the installed org , as the logo was bundled as static resource it cannot be modified so, we are trying to place the image in a document folder and refer it  in VF page but the image is not displaying correctly .  We have tried using  url for the image but it is not working . Your help or a working example  will be appreciated in resolving this issue.

 <apex:image value="{!$Resource.gii__logo}"/>

We are trying to package the application as managed beta. The static resources gets locked in the target org.

So we are not able to change the logo.

Is there any way we can use a logo file from the document folder in 

We already tried using the URL <apex:image url="/document/image/logo.jpg"/>.  But it does not work..

Is there any way to get the URL for the documents within the org itself.

**This is very urgent, **  Your help is much appreciated

Message Edited by p1_dfs on 09-04-2008 06:10 PM
The issue here is not really related to PDF generation - the way you are attempting to refer to a Document will not work in any context. A Document can only be referenced by its id currently and to make things a bit more fun you also need to reference the file download servlet in your url, e.g.:

<apex:image value="/servlet/servlet.FileDownload—file=015x00000009Ki0"/>

this has been a long standing bit of fun with Documents - something that has been on the backlog to be cleaned up to be like static resources from a name reference support standpoint - but for now this is the way it is.

Also, as a general rule when working with pdf generation you'll want to get your page working with renderAs="html" first and then switch it to renderAs="pdf".

sorry to beat a dead horse, but we are still trying to find an answer to our issues:

is it safe to assume then that any document stored outside SF's walls will not work?  What about a file stored in Appirio's Cloud Storage app, for example?   

That is the case currently but we are looking at leveraging the same white listing concept already in place for http callouts in apex code to allow selective and controlled access to external sites - not ETA on this being deployed just yet.
thanks much for the reply Doug.  Good to know this is at least being looked at. 

Your answer seems like the right idea - I completely support the reasons that you need to keep things locked down.  however, in the case of an AppExchange-certified app, exceptions such as you mention would certainly increase the functionality available to the user. 

New problem - Same subject

I have an image stored as a document in

I have the code to retrieve the object, i. e.

<apex:image value="servlet " etc. />

The image displays fine as html.

The image displays fine as pdf, when running as system admin.

The image does not display with any other user profile.

What security setting in system admin needs to be carried to users so they can display the image?
Hi Claiborne,

I don't know of a specific permission that would cause this.  We haven't really seen this pop up yet.  Can the user see the page at all?  Perhaps has something to do with the page security?

Everything is fine on the "user" pdf page except that the image is displayed as a broken link image.

Also, I had problems in the pdf page with a third level data reference -

The field - - did not display unless I changed the user profile to "Read all data".

I ended up creating a reference field slab__c.product__c = to This works fine without enabling the data view.

I have not encountered the situation you are describing. Is there a reason you are using Documents for this instead of Static Resources?
Using Static Resources solved this particular problem (I read Chapter 5), but the strange behavior still exists if I retrieve it as a document - As HTML, image displays for System Admin and other profiles. As PDF, image displays for System Admin, but not for other profiles.

And there is the problem with a 3-deep relational variable.
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!

Doug - this is fantastic news!!  Thank you so much for keeping track of this and helping us out.  


Will this be 'testable' in the sprin '09 preview sandbox orgs? 


Thanks for the tip on setting up the remote site for rendering images as PDFs.


This is allowing the PDF to generate but I am getting different results for the dynamically created image which is in the PDF and in the body of the visualforce email template.


The email version works perfectly. Calling the same code results in the URL for the dynamic image failing to resolve correctly.


<apex:image url="{!relatedTo.ri__dynamic-image-URL__c}" ></apex:image>


The URL is long with 226 chars. Is this a problem in the PDF?

Works fine in the email template