2

I generating the attachment from trigger action, Need to generate the attachment as pdf file, contains image from static resource and value from text area field. I have trying to use blob.toPdf() to convert the pdf,

I am able to generate the pdf file from text area, however not able to add image into pdf file.

Please find below code,

Blob body=[Select Name, ContentType, Body From StaticResource where name='resoursename'].body; 
Attachment attachmentPDF = new Attachment();
attachmentPdf.parentId = cse.id;
attachmentPdf.name = cse.name + '.pdf';
attachmentPdf.body = blob.toPDF('text area values');
insert attachmentPDF;

Could you please let me know how to combine image and text area in single pdf file.

2

You can't directly compose a PDF from a text area and a blog image. Instead, they need to be "rendered" or "Printed" as a PDF in some kind of composition program or what some refer to as a "RIP" (the equivalent of Adobe Acrobat Exchange).

The only way I know of that you can do something like this from within Salesforce is to output the text area content into a VF page and also put the image on the page in an acceptable format such as JPG, PNG, Tiff, etc, then use renderAs = PDF and save the VF page to a file. Your only other alternative would be to use a 3rd party solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.