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
Kelsey DuncanKelsey Duncan 

logo on Visualforce PDF

Hello,

I am trying to add a logo to the top of a Visualforce PDF. I was originally able to do this using 

 <center><apex:image url="{!$Resource.PM_Invoice}" width="300" height="150"/></center>

However I now need the logo to show based on the logo on the Customer Account - as we use this PDF to generate orders for 2 clients.

I have created a custom URL field on the Account (Logo_URL__c) and a second field Logo Image with the formula below:
IF(LEN(Logo_URL__c)=0,"", IMAGE(Logo_URL__c,"Company Logo"))

This shows the logo on the accounts.

I have then referenced both these fields in my Apex Class Controller.

I am now struggling to get the logo to show on the invoice - I have tried using many variations of the below

<center><apex:image url="{!accountDetails.Logo_URL__c}" width="300" height="150"/></center>

and each time just have a greyed out box where the logo should show.

Does anyone have any ideas?

Thanks,

Kelsey

User-added image
 
Kelsey DuncanKelsey Duncan
I also just wanted to mention I have managed to do this at the bottom of the page - using a text field that contains a hyperlink

I created a custom text field Privacy_Policy__c which contains generic text 'Please see our Privacy Policy for more details' - the words in bold are then hyperlinked to each of the clients privacy policy.

I have then used the below to include this in the VF PDF and it has worked perfectly - depending on the account the invoice is created for, the hyperlink is different

<apex:outputField value="{!accountDetails.Privacy_Policy__c}" />

I have tried different variations of this for Logo_URL__c and still face the same issue of a grey box

Thanks
Dushyant SonwarDushyant Sonwar
Hi Kelsey ,

Just wanted to know more about the issue , when you remove the renderAs="pdf" attribute does the image show or is it still as broken?
Is it only happening in pdf generation?

You can try just adding the {!accountDetails.Logo_URL__c} field on vf pdf page to check if the formula is returning you url , or  not.

Hope this helps.
Dushyant SonwarDushyant Sonwar
Hi Kelsey ,

You can also try changing the attribute to see whether this might be issue of the attribute.
<center><apex:image url="{!accountDetails.Logo_URL__c}" width="300" height="150"/></center>

to
<center><apex:image value="{!accountDetails.Logo_URL__c}" width="300" height="150"/></center>

​Hope this helps.
Kelsey DuncanKelsey Duncan
Hi Dushyant,

Thank you for your suggestions! Unfortunately I still couldn't get the image to show on the Invoice.

So I have taken a different approach and created a Text(Rich) custom field on the account called 'Invoice_Logo__c' and inserted the image direct into there.

Then I referenced it similar to my 'Privacy_Policy__c' field and everything is working as it should!! :-) 

<center><apex:outputField value="{!accountDetails.Invoice_Logo__c}" /></center>

Thanks again for your help.

Kelsey
Palash Rana 8Palash Rana 8

You'd need to store the image as a static resource and then reference the resource in your VF page. To access the static resources:
>Setup>Develop>Static Resources

Note that the Cache needs to be set to Public

Once you've placed the static resource you can then use your html markup to reference the image:

Example-> Static Resource's name = Test_Image

<img src="{!$Resource.Test_Image}"></img>


Should do the trick!