In every business generating PDF files from invoices, bills, articles, reports, etc. is necessary. As a PDF (portable document file), we can keep it offline for later consumption instead of viewing the same detail using the network.
In this post, we will explain how to Generate PDF in Salesforce on button click. In this implementation, we will show Generate PDF button in Salesforce on the Account details page. After clicking a button, a PDF will be generated.
Salesforce has in-build PDF generation tool, that can generate PDF document dynamically without using any third party app. Later generated PDF can be saved as File on Salesforce Record or can be sent via Email.
Table of Contents
To create a static resource:
To create Visualforce pages :
<apex:page id="MyFirstPDF" standardController="Account" renderAs="pdf">
<body>
<div class="" style="min-height: 2in;">
<!-- SECTION: header w/ company address and logo -->
<table class="header-table">
<tr>
<td style="width: 75%">
<apex:image width="2.75in" url="{!$Resource.companyLogo}"/>
</td>
<td style="">
<table style="width: 2.8in;border: solid 1px black; border-collapse: separate; ">
<tr>
<td style="text-align: center; font-size: 16pt; font-weight: bold; border-bottom: solid 1px black"
colspan="2">Invoice Summary
</td>
</tr>
<tr>
<td> Date:</td>
<td style="text-align:right;">
{!DAY(TODAY())}-{!MONTH(TODAY())}-{!YEAR(TODAY())}
</td>
</tr>
<tr>
<td> Account:</td>
<td style="text-align:right;">Jack-Rich </td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<table >
<tr>
<td >Address:</td>
<table Style="padding-left: 90px;">
<tr>
<td>
Jack-Rich
</td>
</tr>
<tr>
<td>
1704 Weeksville Road
</td>
</tr>
<tr>
<td>
Elizabeth City, 27909
</td>
</tr>
</table>
</tr>
</table>
<br/>
<br/>
<br/>
<div style="min-height: 5.7in;">
<table style="width: 100%;">
<tr>
<th>Date</th>
<th>Billing</th>
<th>Email</th>
<th style="text-align:right;">Paid Amount</th>
<th style="text-align:right;">Due Amount</th>
<th style="text-align:right;">Total Amount</th>
</tr>
<tr>
<td>01-01-2022</td>
<td>000001</td>
<td>example@gmail.com</td>
<td style="text-align: right;">$1000</td>
<td style="text-align: right;">$9000</td>
<td style="text-align: right;">$10000</td>
</tr>
<tr>
<td>04-01-2022</td>
<td>000002</td>
<td>example1@gmail.com</td>
<td style="text-align: right;">$2500</td>
<td style="text-align: right;">$8500</td>
<td style="text-align: right;">$11000</td>
</tr>
<tr>
<td>11-02-2020</td>
<td>000003</td>
<td>example2@gmail.com</td>
<td style="text-align: right;">$4000</td>
<td style="text-align: right;">$8000</td>
<td style="text-align: right;">$12000</td>
</tr>
<tr>
<td>17-03-2020</td>
<td>000004</td>
<td>example3@gmail.com</td>
<td style="text-align: right;">$4400</td>
<td style="text-align: right;">$6000</td>
<td style="text-align: right;">$10400</td>
</tr>
<tr>
<td>09-04-2020</td>
<td>000005</td>
<td>example4@gmail.com</td>
<td style="text-align: right;">$7000</td>
<td style="text-align: right;">$2000</td>
<td style="text-align: right;">$9000</td>
</tr>
<tr>
<td><b>Total</b></td>
<td></td>
<td></td>
<td style="text-align: right;"><b>$19300</b></td>
<td style="text-align: right;"><b>$33500</b></td>
<td style="text-align: right;"><b>$51400</b></td>
</tr>
</table>
</div>
<div class="footer" style="">
<hr/>
<table align="center" style="width: 100%;">
<tr>
<td colspan="2" style="font-size: 10pt; color: green;">
<table style="width: 100%; border-collapse: collapse; border: 1px solid black; ">
<tr>
<td style="text-align: left;">Arrify</td>
<td style="text-align: right;">www.arrify.com</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</apex:page>
To Create a Button on Account
"Generate PDF"
.Generate PDF
" into the Custom Buttons area on the page layout.Visualforce PDF rendering supports a limited set of fonts. To ensure that PDF output renders as you expect, use the supported font names. For each typeface, the first font-family name listed is recommended.
Typeface | font-family Values |
---|---|
Arial Unicode MS | Arial Unicode MS |
Helvetica | sans-serif, SansSerif, Dialog |
Times | serif Times |
Courier | monospace Courier Monospaced DialogInput |
Parameter | Custom Code | S-Docs | PDF Butler |
---|---|---|---|
Setup Cost | $250 - $400 (Based on document) | $200 | $160 |
Subscription Cost (For 10 Users) |
$0 | $125/Month* (*Anual Contract) |
$140/Month |
Speed | Fastest | Moderate | Slow |
Security | Most Secure (No external service) |
Moderate | Depends on Their Server |
Updates | Not Needed | Need to install update in every release |
There are multiple apps that can generate PDFs in Salesforce. Most of them are paid and pull data from Salesforce to their server and output will be pushed back to Salesforce. This method took some extra time compared to native Salesforce PDF generation. Also, there are some data security issues.
Top apps on app exchange:
Tag line: Efficiently create and manage your documents in Salesforce
Pricing: Starting from $200/month ($20/user/month with 10 minimum users required)
Tag Line: Native Document Generation & E-Signature: PDF, Word, XLS, Email, Reports
Pricing: Starting from $1500/Year (1-10 Users $1,500)
PDF in salesforce can be generated easily without using any other app. That can work in Salesforce Lightning as well as Salesforce Classic.
Cost depends on how you generate PDF. By using a third-party app there will be a monthly cost (per user based) along with the initial setup cost. By using visualforce, it's completely free from monthly cost, it requires initial setup only.
Generating a PDF within Salesforce can be done with VisualForce and Apex. It is very easy (even for those with very little VisualForce and Apex experience). You are able to generate any Salesforce page as a PDF by adding the renderAs attribute to the component, and specifying “pdf” as the rendering service.
We first need to create a Visualforce page that will have the PDF Content. Below is the simple Visualforce page that will display Account details with the help of the Account Standard Controller.