How to have a Visualforce Page Download as a pdf

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

Brian is a software architect and technology leader living in Niagara Falls with 13+ years of development experience. He is passionate about automation, business process re-engineering, and building a better tomorrow.

Brian is a proud father of four: two boys, and two girls and has been happily married to Crystal for more than ten years. From time to time, Brian may post about his faith, his family, and definitely about technology.