I want to convert a Visualforce to Pdf and preserve the visualforce css styling the same time in the generated PDF. I am able to achieve the first part using the attribute renderas='pdf'. However the styles are getting lost. Any pointers if and how both can be achieved at the same time.

2 Answers 2


When we add renderas='pdf' then Salesforce create PDF in server side in that process we lost many CSS which are not compatible with Salesforce's PDF engine.

You can try renderAs="advanced_pdf" to render in PDF. It support much better CSS but also have some limitation. You can read them in details here: Use Advanced PDF to Render Visualforce Pages as PDF Files (Pilot).

Another thing which you can do is renderas='{!DynamicType}' you can also pass a dynamic type(HTML or PDF) here and based on your use case display the rendered PDF or a normal Visualforce page.

  • advanced_pdf is still in pilot last time I checked? Commented Apr 12, 2018 at 9:51
  • @PranayJaiswal yes thats why I have mentioned that it has some limits as well. Commented Apr 12, 2018 at 9:55

You can generate a downloadable, printable PDF file of a Visualforce page using the PDF rendering service. Convert a page to PDF by changing the tag.

<apex:page renderAs="pdf">

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .