I've tried some searching and it's unclear to me if what I want to do is possible in Salesforce. I have an image file attached to a Salesforce Case, and I want to use an <apex:page showHeader="false" renderAs="pdf">
to build a PDF with that file embedded in it.
The image is a drawn signature, to produce a signed PDF, so this image is confidential.
I've tried an image that looks something like:
<apex:image url="{!imageURL}"></apex:image>
Where the imageUrl in my Aura controller is something like
public String imageURL{
get {
List<ContentVersion> vers = [SELECT Id, ContentDocumentId FROM ContentVersion ORDER BY CreatedDate DESC];
ContentVersion v = vers.get(0);
return '/servlet/servlet.FileDownload?file=' + v.ContentDocumentId;
}
}
This renders a broken image in the PDF.
I've also tried to Base64 encode the image and pass that to the template, something like:
<img src="data:image/jpg;base64,{!imageContent}"/>
With the controller code:
public String imageContent {
get {
List<ContentVersion> vers = [SELECT Id, VersionData FROM ContentVersion ORDER BY CreatedDate DESC];
ContentVersion v = vers.get(0);
return EncodingUtil.base64Encode(v.VersionData);
}
}
When viewing the visualforce page (I created a tab for it) in both cases the image appears as a broken image using an icon that was created in 1927:
If I spit out the image base64 contents directly onto the page:
<p>"{!imageContent}"</p>
And I copy that content and then in vanilla HTML I build an image with that base64 encoded data as the src, the image renders properly. So I know this is a valid base64 encoding of the jpg binary data.
Is it possible to embed an image from a File / ContentVersion in a VisualForce rendered PDF?
<apex:image value="...">
(you usedurl=
)