+ Start a Discussion
Nadia GainsbourgNadia Gainsbourg 

How to reference a PDF file in a VF code

I've created a custom link that brings up a VF page that should display an image file (instructions for the reps). 

1. How to I reference the image file in VF code?
2. Where and how do I store the actual image file in Salesforce? 

Thank you!
Rakesh Thota 15Rakesh Thota 15
Hi Nadia Hsu,

Do you want a quick solution ?
Define a global js variable with the path from the visualforce page :
var globalStaticResourcePath = '{!URLFOR($Resource.thenameofyourzipfile)}';
and inside the js, every time that you are going to put the img url , add the global url var, example:
(inside script.js that is in the zip file)
var imgpath = globalStaticResourcePath+'image.jpg';


store the image as static resource file and use it in VF page, as shown below. I have tested with two lines; it is working for me
<apex:page >
<apex:image value="{!URLFOR($Resource.vfimagetest,'cats/kitten1.jpg')}"/>
<apex:image value="{!URLFOR($Resource.vfimagetest,'cats/kitten1.jpg')}"/>

Hope this code will help you to fix your issue. Make it solved if its works for you.

Best Regards,
Rakesh Thota.

Rakesh Thota 15Rakesh Thota 15
Hi Nadia Hsu,

To refer a PDF file in a visualforce page, convert the PDF file to PNG and put it in static resource. Then, I recuperate this resource in your Visualforce page.

Hope this helps you!

Best Regards,
Rakesh Thota.

Hi Nadia,

Most the time when we store image in the static resource we faced some issue like image not display.
If you are facing such issue so please store image in the document and please make sure check the externally available chekcbox in the document.

Gyanender Singh