Creating PDF In Salesforce

|
| By Webner

How to create PDF In Salesforce using Visualforce?

We can create Pdf using Visualforce page, here is sample code to create Pdf. The renderAs Method is used to download/view the Page as Pdf, Excel, Doc etc.

<apex:page sidebar="false" showHeader="false" applyHtmlTag="false" standardStylesheets="false" renderAs="pdf">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
            <style> 
            @page { 
                size: auto;   /* auto is the initial value */ 
                
                /* this affects the top and right margin in the printer settings */ 
                margin-top: 10mm; 
                margin-right: 10mm;
            } 
            body {
                font-family: Arial Unicode MS;
                margin:0px;
            }
            
            </style>
        </head>
        <body>
            <div class="header" width="100%">
                <table style="font-family: serif; font-size: 10pt; color: #00000;padding-bottom: 100px;" width="100%">
                    <tbody>
                        <tr>
                            <td width="60%"><b>Webners Solution</b></td>
                            <td width="15%"><b>Date: </b><apex:outputText value="{0,date,MM/dd/yy}"> <apex:param value="{!TODAY()}" /> </apex:outputText> </td>
                        </tr>
                    </tbody>
                </table>
           </div>
           <div class="content" width="100%">
                <table style="font-family: serif; font-size: 10pt; color: #00000;padding-bottom: 400px;" width="100%">
                    <tbody>
                        <tr>
                            <td width="20%"><b>Our Reference</b></td>
                            <td width="20%"><b>Date</b></td>
                            <td width="20%"><b>Type</b></td>
                            <td width="20%"><b>Your Reference</b></td>
                            <td width="20%"><b>Net Amount</b></td>
                        </tr>
                        <tr>
                            <td width="20%">Deepika Saini</td>
                            <td width="20%"><apex:outputText  value="{0,date,MM/dd/yy}"> <apex:param value="{!TODAY()}" /> </apex:outputText> </td>
                            <td width="20%">Check</td>
                            <td width="20%">123456</td>
                            <td width="20%">$1000</td>
                        </tr>
                    </tbody>
                </table>                
            </div>
        </body>
    </html>
</apex:page>

Salesforce provides pdf viewer to view the Pdf in the web browser.

Output:-

Salesforce

Leave a Reply

Your email address will not be published. Required fields are marked *