function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SidharthSidharth 

Open HTML Email template as pdf

Can we open a HTML Email template as pdf using Custom link/button, so user can print/save the document.
Rakesh KumarrRakesh Kumarr
Hi Sidarth ,

You can do this .Please write a apex class to read the content of your email template.Then parse the merge fields and replace them with the values .Build a apex page and save it as pdf .Call this from a link or button .This can be the solution for this .

Hope solution helps !!

Regards,
Rakesh
SidharthSidharth
Thanks Rakesh. I tried that, but somehow when i am rendering the vf page as pdf, and outputing the 
HTMLValue of the email template, its just showing html code, but not rendering as html web page. 

Page
<apex:page controller="Test" renderAs="pdf">
<apex:outputText value="{!testTemplate.HTMLValue}" escape="false"/>
</apex:page>

Controller
testTemplate = [Select id,Body,Subject,DeveloperName,HtmlValue from EmailTemplate where DeveloperName = :templateName];

Anything i am missing ?
Rakesh KumarrRakesh Kumarr
I will get back to you soon with solution !!
Rakesh KumarrRakesh Kumarr
you are doing it in correct way ... try putting the html value in the string and access that string .do you have any merge fields in your template ?? if yes then you need to write a parser for that which parse your full template ....and generate code for pdf .!! Let me know soon !!!
Rakesh KumarrRakesh Kumarr
<apex:page controller="cntrlr name" renderAs="pdf" cache="false" showHeader="false" sidebar="false" showChat="false">
    <apex:outputText value="{!pdfContent}" escape="false"/>
</apex:page>
SidharthSidharth
Still same result. 

Controller
public class Test_Sid{
    public String pdfContent    {get;set;}   
    public Test_Sid(){
        pdfContent = [Select id,Body,Subject,DeveloperName,HtmlValue from EmailTemplate where id = '00X23000000QAnY'].HTMLValue;
    }
}

Page
<apex:page controller="Test_Sid" renderAs="pdf" cache="false" showHeader="false" sidebar="false" showChat="false">
<apex:outputText value="{!pdfContent}" escape="false"/>
</apex:page>



 
Rakesh KumarrRakesh Kumarr
Check your query once I am not sure about that !!
Michael MMichael M
Hey, I am trying to do the same now. Were you able to do this in the end?