How to have a Visualforce Page Download as a pdf

Salesforce Logo
Sharing is Caring

When creating applications it’s a pretty common request to be able to create a formatted report or file in pdf file format.

For the most part, most customized pages and data can be easily converted into a PDF file without having to make many changes. In Salesforce, we can change customized Visualforce pages to create a pdf file by using the renderAs property and set the value to pdf.

<apex:page standardController="Contact" renderAs="pdf" >

If we need to do a page break after a certain section, we can do this with css. If we wrap our content with a div and apply the style “page-break-after: always” the content after will be on a new page.

<div style="page-break-after: always">Some content</div>

We can do some pretty sophisticated pages and layouts by using CSS3 and the @page rule.

Sharing is Caring