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

Render PDF in Visualforce Using Dynamic HTML
I am trying to create a simple VF page that renders a PDF from HTML that is passed in by my controller. Using the VF code below, the dynamic HTML renders properly as a regular VF page, but when I add the "renderAs="PDF" to my page tag, only the raw HTML appears in the PDF and not the properly rendered HTML.
The following correctly renders the dynamic HTML:
<apex:page controller="trainingLetterPDFController" > <apex:outputText value="{!LetterHTMLBody}" escape="false"/> </apex:page>
The following renders the page as a PDF showing the raw HTML text:
<apex:page controller="trainingLetterPDFController" renderAs="PDF"> <apex:outputText value="{!LetterHTMLBody}" escape="false"/> </apex:page>
Any suggestions on how to get this dynamic HTML to render in the PDF?
Thanks!
You probably need to use proper controller side encoding to the LetterHTMLBody variable. It appears that the variable value is being treated as text when it's rendered as PDF.
Thanks!
Hi,
It seems like, while rendering PDF it escapes the HTML tags when used dynamically.
If it is possible in your scenario, create a visualforce component containing the dynamic HTML part of the your page and then include that component wherever you are using the field "LetterHTMLBody".
You can refer the following sample code:
Controller class:
Page:
Component:
Hope this helps you!
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank you,
Neeraj
Thanks, Neeraj and asawant. I will give this a try and will give kudos. In the meantime, I am posting my original controller code for some context.
The controller is accessing the HtmlValue of an email template, and this is ultimately what I am passing to my VF page to produce the PDF.
Hi,
You can go with the approach I have mentioned above, by using the htmlvalue in the component and adding component in the visualforce page.