4

I am trying to get a report containing images rendered as a PDF. When it renders as a PDF all the images break, but when I switch it to HTML, they work fine. Anyone know why these would not work when rendered as a PDF?

My VF page code is below.

<apex:page standardController="Opportunity" recordSetVar="SelectedOpportunities" renderAs="pdf" > 
<apex:variable var="number" value="{!0}"/> 
        <apex:repeat value="{!selected}" var="SelectedOpportunity">
        <apex:outputText rendered="{!MOD(number,8)==0}"><p align="center" style="{!IF(number!=0,'page-break-before: always;','')}"></p></apex:outputText>
        <apex:variable var="number" value="{!number + 1}"/> 
        <apex:outputText rendered="{!MOD(number,2)==1}">
        <div style="width:350px; float:left; border:1px solid black">
        <table>
            <tr>
                <td width="200px" height="200px">
                    <apex:outputText value="{!SelectedOpportunity.Student_Image__c}" escape="false"/>
                </td>
        <td width="150px" height="200px"><span style="font-weight: bold">   
                {!SelectedOpportunity.Full_Name__c} </span> <br /> 
                {!SelectedOpportunity.City__c}, {!SelectedOpportunity.State__c}  {!SelectedOpportunity.Country__c}<br />
                {!SelectedOpportunity.Voyage_Code__c}
            </td>
        </tr>
        </table>
        </div>
    </apex:outputText>
    <apex:outputText rendered="{!MOD(number,2)==0}"><div style="width:350px; float:right; border:1px solid black">
        <table><tr>
        <td width="200px" height="200px">
            <apex:outputText value="   {!SelectedOpportunity.Student_Image__c}" escape="false"/>
        </td>
        <td width="150px" height="200px"><span style="font-weight: bold">   
            {!SelectedOpportunity.Full_Name__c} </span> <br /> 
            {!SelectedOpportunity.City__c},{!SelectedOpportunity.State__c}  
            {!SelectedOpportunity.Country__c}<br />
            {!SelectedOpportunity.Voyage_Code__c}
        </td>
        </tr>
        </table>
    </div>      
   </apex:outputText>
</apex:repeat>

1 Answer 1

2

You should not use escape equals false and don't encourage this as this is a security risk .

         <apex:outputText value="{!SelectedOpportunity.Student_Image__c}" escape="false"/>

Instead of above I would use the URL and use img tag

<img src="URL"/>

or Apex:image tag

 <apex:image value="url merge field"/>

You must log in to answer this question.

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