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.
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.
-
-
@PranayJaiswal yes thats why I have mentioned that it has some limits as well. – Tushar Sharma Apr 12 '18 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">