How do I convert a visualforce page to a PDF? Please provide a code sample.

2 Answers 2


You can use : apex:page renderAs="pdf" showHeader="false"

Than whenever that page open it download as a pdf

  • 2
    It only rendres a page as PDF. The user need to download it yourself. Commented Dec 20, 2012 at 12:58
  • 1
    @mast0r I think that depends on the browser, older browsers probably make you download it as a file when they are not capable to display it. Commented Dec 20, 2012 at 13:20
  • Yes, it can be but without a normal filename. For my org it is very important to have custom filenames. Commented Dec 20, 2012 at 13:22

If you need not only convert your page to PDF but save this file with a specific name here is a workaround. You will need two pages – the first page generates an PDF file and the second saves it with specific filename:

The main "wrapper" page saves PDF and gives a filename:

<apex:page id="MainPage"

    <!-- Here comes another page with a content to be converted to PDF -->
    <apex:include pageName="PageThatGeneratesPdf"/>

PageThatGeneratesPdf – only generates PDF content:

<apex:page showHeader="false"

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

<style type="text/css">
    size:A4 portrait;

    @bottom-right {
        content: "Page " counter(page) " - " counter(pages);
        font-family: 'Arial', 'Helvetica', sans-serif;

Here is your main content ...


You must log in to answer this question.

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