16

I'm trying to generate a Visualforce PDF (renderAs) with a variety of images from different sources includes Salesforce Attachments and Documents, as well as third party sites. So far I've only been able to display images stored as static resources, or stored in zipped static resources.

Is it possible to use images which are not stored as static resources in Visualforce-generated PDFs?

1
  • i am running into a similar issue wanting to use bootstrap for my PDF and one of the css files references a different folder for fonts in the form src:url('../fonts/gly..etc) and it looks like its not resolving the '../' in the file path. these are static resources so no need for remote settings. i was thinking of moving the fonts in the same folder but was hoping i wouldnt have to change the file structure of bootstrap.
    – textual
    Commented Mar 1, 2014 at 5:07

5 Answers 5

15

This should be possible: we do this in FinancialForce Accounting via the servlet.fileDownload URL that salesforce provides for downloading documents to include company logos on PDF financial documents.

The trick is that any external URLs you want salesforce to make a HTTP(s) call to need to be defined under Setup > Security Controls > Remote Site Settings. Make sure the protocol (HTTP vs HTTPS) matches the image link!

A followup edit that it appears that the older PDF rendering engine (pre APIv24?) does not pass a session ID when requesting images from salesforce documents. I made the image externally available and it worked - note that this changes the URL from servlet.FileDownload to servlet.ImageServer as well. V25 seems to pass the session ID as expected so far.

6
  • 2
    Seems a good trick - do you have a full version of the URL to pull from?
    – joshbirk
    Commented Jul 31, 2012 at 22:29
  • Relative URLs work, as do absolute URLs. The format for document-based images is /servlet/servlet.FileDownload?file=<doc id> or https://<instance>.salesforce.com//servlet/servlet.FileDownload?file=<doc id> Commented Jul 31, 2012 at 22:45
  • Does that translate into something which can be used as a proxy for external images, like: /servlet/servlet.FileDownload?docid=google.com/logos/classicplus.png?
    – joshbirk
    Commented Jul 31, 2012 at 23:13
  • @joshbirk, do you mean is there a security hole a mile wide in the platform? I hope not!!
    – jkraybill
    Commented Jul 31, 2012 at 23:42
  • 1
    Thank you @ca_peterson I got this to work with externally hosted images on Amazon. I had to edit the remote site setting and add a site URL similar to mlsvc01-prod.s3.amazonaws.com and then my static image reference works perfectly. Thank you
    – Joseph U.
    Commented Aug 1, 2016 at 17:28
7

Yes, you can. I've done it. The (undocumented) trick is that you need to have Remote Site Setting records setup for the domains where the external URLs are hosted.

2

As in a standard img src="http://someurl.com" - I don't believe so. Testing it with either http or https in the image source results in a broken PDF image for me.

Edit: The other comments are correct, this works if Remote Site Setting is setup. My test earlier was cached.

1

We've had a little bit of success putting regular image URLs into our VisualForce PDFs by just using ''. However, there are some images that just won't generate properly, so we've had to set them up as static resources and haven't been able to get them to render without doing it that way. We thought it might have something to do with SSL or the file types, but don't think that's the case. Anyone else have experience with this?

1
  • when you say 'by just using ""', do you mean <img src="...">?
    – paul
    Commented Jul 31, 2012 at 21:46
1

Image uploaded as document can also visible in pdf page

1
  • 1
    Shailendra, I recommend you visit our Help center and read How do I write a good answer?. Your answer is more of a comment as it doesn't provide sufficient details to be considered a complete answer. Would you like to add detailed instructions or provide a link to documentation on how one would add an uploaded document image to a PDF page?
    – crmprogdev
    Commented Jan 23, 2015 at 19:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .