Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 9 down vote accepted

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

Than whenever that page open it download as a pdf

share|improve this answer
It only rendres a page as PDF. The user need to download it yourself. – Sergey Utko Dec 20 '12 at 12:58
@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. – Samuel De Rycke Dec 20 '12 at 13:20
Yes, it can be but without a normal filename. For my org it is very important to have custom filenames. – Sergey Utko Dec 20 '12 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 ...

share|improve this answer
thanks mastOr this code is really helpfull to me – rakesh Dec 20 '12 at 12:17
An alternative approach to setting the file name is to set the content-disposition header:… – Peter Knolle Jan 1 '13 at 13:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.