So i have an object which holds an attachment. this object is pretty much an invoice and has the option to be turned into a pdf document for printing purposes. the invoice will hold an image as an attachment within itself. now i need to figure out how to make the image show up on the pdf? the pdf is a visual force page with renderAs="pdf" on it i need to kno how to reference the attachment of any invoice object when i click the "Print PDF" button on any individual invoice.

Help Please

  • Are you talking about displaying an Image within the PDF when it is rendered? Jun 26 '13 at 17:47
  • yes thats exactly what i mean Jun 27 '13 at 13:58

assuming there's only one Attachment related to the invoice, this will do the trick

<apex:page standardController="Invoice__c" renderAs="PDF">

  <apex:repeat value="{!Invoice__c.Attachments}" var="a">
       value="{!URLFOR($Action.Attachment.Download, a.Id)}"/>

     <apex:outputText value="{!a.Name}"/>


  • This works now how about if i wanted the name of the file to appear under the image and what if i had more than one attachment but that number could change depending on the object. anywhere between 0 and however many people wanted to put on it. Jun 27 '13 at 14:20
  • the solution works well for multiple attachments, wasnt really sure if you wanted to some more then one. Updated to the code show the Filename was well
    – Seb Wagner
    Jun 27 '13 at 15:21
  • nevermind i got it Jun 27 '13 at 15:51

In your visualforce page, you would simply need to make reference to the URL of the Image, for example:

<img src="/servlet/servlet.FileDownload?file=015b00000005mrz"/>

Where /servlet/servlet.FileDownload?file=015b00000005mrz is a reference to an Image stored as a Document within Salesforce.

You need to make sure your image is externally available I believe.

  • hmm, think i misunderstood what you wanted Jun 27 '13 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.