Find your content:

Search form

You are here

How do I convert a visualforce page to a PDF?

 
Share

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


Attribution to: rakesh

Possible Suggestion/Solution #1

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

Than whenever that page open it download as a pdf


Attribution to: D-Horse

Possible Suggestion/Solution #2

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"
           showHeader="false" 
           cache="true"
           contentType="application/x-pdf#Here-is-your-filename.pdf">

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


PageThatGeneratesPdf – only generates PDF content:

<apex:page showHeader="false"
           renderAs="PDF"
           cache="true">

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

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

    @bottom-right {
        content: "Page " counter(page) " - " counter(pages);
        font-family: 'Arial', 'Helvetica', sans-serif;
        font-size:10px;
    }
}
</style>
</head>

Here is your main content ...

</apex:page>

Attribution to: Sergej Utko
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5605

My Block Status

My Block Content