I am trying to display an image in my PDF but am unsuccessful. I am using files to attach the images. Can someone please find out where I am going wrong?
Apex code:
public class findImageAttach {
public ID accountID {get; set;}
public String imageURL{get;set;}
public findImageAttach(ApexPages.StandardController controller){
accountID = ApexPages.currentPage().getParameters().get('id');
List<ContentVersion> documentList = new List<ContentVersion>();
AggregateResult[] groupedResults = [SELECT COUNT(ID) FROM ContentVersion where Account_Name__r.id =: accountID];
System.debug('groupedResults size: ' + groupedResults.size());
if(groupedResults.size() > 0)
{
imageURL='/servlet/servlet.FileDownload?file=';
documentList=[SELECT id, Title, ContentDocumentId, ContentDocument.id,ContentDocument.LatestPublishedVersionId FROM ContentVersion ORDER BY CreatedDate DESC LIMIT 1];
System.debug('documentList title: ' + documentList[0].Title);
System.debug('ContentVersion id: ' + documentList[0].id);
System.debug('ContentDocumentId from ContentVersion: ' + documentList[0].ContentDocumentId);
System.debug('ContentDocument.id: ' + documentList[0].ContentDocument.id);
System.debug('ContentDocument.LatestPublishedVersionId: ' + documentList[0].ContentDocument.LatestPublishedVersionId);
if(documentList.size()>0)
{
//imageURL=imageURL+documentList[0].id;
imageURL=imageURL+documentList.get(0).ContentDocumentId;
System.debug('imageURL: ' + imageURL);
}
}
}
}
VF code:
<apex:page standardController="Account" showHeader="false" standardStylesheets="false" renderAs="pdf" id="mypage" applyBodyTag="false" extensions="findImageAttach">
<body>
<apex:form>
<apex:image url="{!imageURL}">
</apex:image>
</apex:form>
</body>
</apex:page>
I believe the problem is I am using the incorrect id for the attached image and therefore it doesn't render in VF properly.