0

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.

1

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.

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

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">

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.