You need to sign in to do that
Don't have an account?

Embedding an image in PDF attachment using html tags and Blob.toPdf()
I want to add an image to a pdf I am creating and attach it to an email that I send via apex code. I am using html and Blob.toPdf() to make the pdf. I saw this post regarding Blob.toPdf()'s limitations on images: https://help.salesforce.com/apex/HTViewSolution?id=000123577&language=en_US. It says:
"To work around this Blob.toPdf()'s limitation you may resort to one of the below approaches:
1. Store the image as a static resource and then use it in code.
2. Use a Visual Force Page and render it as pdf "
So I tried both ways, the first one throws an error: "An error occurred while parsing the input string" (which happens with <img> tag no matter what src I use).
And the second way is not an option for me cause I have to get the page content that I'm rendering as pdf and attach it to my email BUT "Page.getContent() does not work in Triggers or Email Services".
Is there a work around this limitations?
"To work around this Blob.toPdf()'s limitation you may resort to one of the below approaches:
1. Store the image as a static resource and then use it in code.
2. Use a Visual Force Page and render it as pdf "
So I tried both ways, the first one throws an error: "An error occurred while parsing the input string" (which happens with <img> tag no matter what src I use).
And the second way is not an option for me cause I have to get the page content that I'm rendering as pdf and attach it to my email BUT "Page.getContent() does not work in Triggers or Email Services".
Is there a work around this limitations?
We had a similar requirement in one of our projects and find the way we followed and check if it suffices .
- We had a field on the object called Logo which was a Rich Text Area Field from which user could upload images in the record.
- We created a VF Page for the PDF representation on VF page and displayed that field logo using <apex:outputField />
- Now we got the page content as BLOB as follows
- Now we created an attachment with this BLOB body and sent the mail with this attachment.
It worked for us .. Hope it helps you.
Please mark the answer as best answer or like it if it helps :)
All Answers
We had a similar requirement in one of our projects and find the way we followed and check if it suffices .
- We had a field on the object called Logo which was a Rich Text Area Field from which user could upload images in the record.
- We created a VF Page for the PDF representation on VF page and displayed that field logo using <apex:outputField />
- Now we got the page content as BLOB as follows
- Now we created an attachment with this BLOB body and sent the mail with this attachment.
It worked for us .. Hope it helps you.
Please mark the answer as best answer or like it if it helps :)
Please help me in this, i also have a similar situation, a small change that i need to store that as an attachment to a record.
From 1st VF page controller:-
A record has been saved with a rich text field includes text and images.
PageReference pageDoc = Page.pdfDoc;
pageDoc.getParameters().put('id','00B4B000000YpYb');
//to get 2nd page content
Blob body;
body=pageDoc.getContent();
//attch file to a record
Attachment attachmentFile = new Attachment();
attachmentFile.parentId = parentId;
attachmentFile.Name = 'abc.pdf';
attachmentFile.body =body;
insert attachmentFile;
On 2nd Page VF page (pdfDoc VF page):-
<apex:page renderAs="pdf" standardController="Object__c">
<apex:outputField value="{!Object__c.RichTextField__c}"/>
</apex:page>
Rich text field includes text and images.
But i am unable to save it as an attachment , as i got the following error:- "common.apex.runtime.impl.ExecutionException: Unable to retrieve object".
Please help me on this.