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
SkiesnPiesSkiesnPies 

Attachment Images Rendered In HTML But Not In PDF

Hi, I have had lots of problems getting a PDF rendered with images that live in attachments. The attachments render beautifully when my VF page is presented in HTML, but as soon as I say renderas="PDF" the images become broken.

Neither of these tags work : 
<apex:image url="https://c.na11.visual.force.com/servlet/servlet.FileDownload?file={!AttachmentID}"/> 
<img src="https://c.na11.visual.force.com/servlet/servlet.FileDownload?file={!AttachmentID}"/>
(note: I deliberately set the URL to the full path during testing / experimentation). 

I have read that you need to set your remote site settings to contain your server, so the PDF generation can look back to Salesforce to see the records, see below for my settings. 

Should this work? Are my remote site settings wrong or did I fundamentally miss something? Thanks in advance. 

Broken Image
Remote site settings
Best Answer chosen by SkiesnPies
SkiesnPiesSkiesnPies
Just for everyones future benefit, in the end, my solution was to store the image as an attachment (where I needed it) and then when I needed to generate the PDF , I copied the attachment image to a document in the users default folder, passed the ID of this document to the VF page that generated the PDF, generate the PDF using the image in the documents folder, store the PDF as an attachment and then delete the document from the folder.

This way I could get around the problem (bug??) of not being able to see attachments but still retain the image as an attachment. Poor that I had to work around in this way, but its a workaround that seems effective. 

All Answers

Swayam@SalesforceGuySwayam@SalesforceGuy
Hi,

Use Static Resource to Put the image, instead of Document, It will work for PDF


--
Swayam
@salesforceguy
SkiesnPiesSkiesnPies
Problem is the images are dynamic - ie. specific to their parent records and added by the user community - so I think attachments are the only place for the image to live. 
SkiesnPiesSkiesnPies
Just for everyones future benefit, in the end, my solution was to store the image as an attachment (where I needed it) and then when I needed to generate the PDF , I copied the attachment image to a document in the users default folder, passed the ID of this document to the VF page that generated the PDF, generate the PDF using the image in the documents folder, store the PDF as an attachment and then delete the document from the folder.

This way I could get around the problem (bug??) of not being able to see attachments but still retain the image as an attachment. Poor that I had to work around in this way, but its a workaround that seems effective. 
This was selected as the best answer