function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gdkgdk 

Visualforce page download as a PDF when Button click

Hi All ,
            I have a Requirement to Download the Visualforce Page as PDF When click on CommandButton


Here I have 2 - Visualforce Pages i have placed a Command Button in One of the Visualforce page when i click on this button the other visualforce page will Download as a PDF without pageredirection


Plese give me a Solution and Thanks in advance...
Best Answer chosen by gdk
Sagar PareekSagar Pareek
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. First page generates an PDF file and 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;
    }
}
</stype>
</head>

Here is your main content ...

</apex:page>


All Answers

Sagar PareekSagar Pareek
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. First page generates an PDF file and 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;
    }
}
</stype>
</head>

Here is your main content ...

</apex:page>


This was selected as the best answer
Sridhar BonagiriSridhar Bonagiri
Hi,

You can use 'renderAs="pdf"' tag in Visualforce Page definition.

<apex:page renderAs="pdf">

Regards,
Sridhar Bonagiri
rajesh kumar 434rajesh kumar 434
create a button in visualforce page and click on button  all data of the object is downloaded
 
rajesh kumar 434rajesh kumar 434
any example
 
EstherEsther

Here you can find examples: 

Visualforce download as PDF (https://arrify.com/generate-pdf-in-salesforce/)

Prakhyat sapraPrakhyat sapra
Hiii 
Sagar Pareek

Thanks in advance 
this code is working in the android but not in ios & can you open the browser on the clicking on the button no only on the preview in android & ios both