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
manubkkmanubkk 

PDF rendering issue in Sites

I have a piece of HTML string which needs to be rendered as PDF. This piece of HTML is dynamic, i.e., the contents are not known in advance.

 

I am using the following code to render as pdf and prevent escaping of HTML:

 

<apex:page controller="ControllerPdf" renderAs="pdf">

  <apex:outputText value="{!HTMLString}" escape="false"></apex:outputText>

</apex:page>

 

This works perfectly in developer mode! But when I access via Sites the HTML is escaped! It just spits out the HTML as it is in the PDF.

Is this a limitation of Sites or is there any setting related to Sites that I should be looking at?

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
Ispita_NavatarIspita_Navatar

 

Hi,                                               

When I tried this code at my end on public sites its working fine , it will escape HTML syntax through escape="false".Make sure you are not doing any work in the source code.


VF CODE:-

                   <apex:page controller="ControllerPdf" renderAs="pdf">

                             <apex:outputText value="{!HTMLString}" escape="false"></apex:outputText                                

                    </apex:page>

           

Controller code:-

                     public class ControllerPdf

                          {

                               public string getHTMLString()

                                    {

                                             string s  = '<a><label style="color:red">The chatter Group</label></a>';

                                             return s;

                                    }

                            }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

Ispita_NavatarIspita_Navatar

 

Hi,                                               

When I tried this code at my end on public sites its working fine , it will escape HTML syntax through escape="false".Make sure you are not doing any work in the source code.


VF CODE:-

                   <apex:page controller="ControllerPdf" renderAs="pdf">

                             <apex:outputText value="{!HTMLString}" escape="false"></apex:outputText                                

                    </apex:page>

           

Controller code:-

                     public class ControllerPdf

                          {

                               public string getHTMLString()

                                    {

                                             string s  = '<a><label style="color:red">The chatter Group</label></a>';

                                             return s;

                                    }

                            }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer
Sridhar BonagiriSridhar Bonagiri

Hi,

 

I think there is no error in your code, but still wondering why it is not coming.

 

 

manubkkmanubkk

Thanks for your answer, that definitely works. The PDF rendering works alright.

 

I figured the problem was not with my visualforce but my controller - I am getting the HTMLString from the query string parameters, there seems to be some problem with the encoding of string when passed as POST parameters, they differ between developer mode and Sites, I will try to figure that out now.

But thanks for the replies.