Generate PDF in Salesforce For free in 2024 [Updated] - Arrify (2024)

Generate PDF in Salesforce For free in 2024 [Updated] - Arrify (1)

In every business generating PDF files frominvoices, 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 with a 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

Steps to generate pdf in Salesforce

  1. Create a Static Resource (optional)
  2. Create a VF page
  3. Create a button to Generate PDF

What you need before start

  1. Your Company Logo image (PNG/JPEG) : Logo will appear on top of generated PDF
  2. Working Salesforce Org

Let's Start generating pdf in Salesforce

Create a Static Resource for your company logo:

To create a static resource:

  1. From Setup, enterStatic Resourcesin theQuick Findbox, then selectStatic Resources.
  2. ClickNew.
  3. In theNametext box, enter the text "companyLogo".
  4. Next to theFiletext box, clickBrowseto navigate to a local copy of your Company Logo.
  5. Set theCache Controlto public.
  6. ClickSave.
Generate PDF in Salesforce For free in 2024 [Updated] - Arrify (2)

Create a Visualforce Page:

Generate PDF in Salesforce For free in 2024 [Updated] - Arrify (3)

To create Visualforce pages :

  1. From Setup, enterVisualforce Pagesin the Quick Find box, then selectVisualforce Pages.
  2. ClickNew.
  3. In theLabeltext box, enter the text "MyFirstPDF". (The same name will be entered into the name)
  4. Copy and paste the below code
  5. ClickQuick Saveto save your changes and continue editing your page. Your Visualforce markup must be valid before you can save your page.
<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>&nbsp;&nbsp;Date:</td> <td style="text-align:right;"> {!DAY(TODAY())}-{!MONTH(TODAY())}-{!YEAR(TODAY())}&nbsp;&nbsp; </td> </tr> <tr> <td>&nbsp;&nbsp;Account:</td> <td style="text-align:right;">Jack-Rich&nbsp;&nbsp;</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>

Create a Detail Page Button on the Account to generate PDF:

To Create a Button on Account

Generate PDF in Salesforce For free in 2024 [Updated] - Arrify (4)
  1. From Setup, clickObject Manager, then clickAccount.
  2. ClickButtons, Links, and Actions, then clickNew Button or Link.
  3. Name the button"Generate PDF".
  4. SelectDetail Page Button.
  5. Set Content Source "Visualforce Page"
  6. Select content "MyFirstPDF"
  7. ClickSave, then clickOK. Now add it to the Account page layout.
  8. ClickPage Layouts, then clickAccount Layout.
  9. From the Buttons category in the palette, drag"Generate PDF"into the Custom Buttons area on the page layout.
  10. ClickSave. OK! Now let’s test it.
  11. From the App Launcher, find and selectSales, then click theAccountstab.
  12. Open an account record.
  13. In the highlights panel, not only do you see the fields from the object’s compact layout, but you also see an actions menu. The actions menu is a combination of the standard buttons, custom buttons, and actions from the page layout.
  14. Expand the actions menu, and selectGenerate PDF. The browser opens a new window or tab that shows you the PDF.

Generate PDF in Salesforce with APEX

Salesforce provides a way to generate PDF documents using Apex, which is a programming language that enables developers to create custom functionality for their Salesforce org. This can be useful for creating documents such as invoices, contracts, and reports.

To generate a PDF with Apex, you can use the PageReference.getContentAsPDF() method. This method allows you to create a new page reference and set the content type to PDF.

Here's an example of how you might use it:

// Create a new page referencePageReference MyFirstPDF = new PageReference('/apex/MyFirstPDF');// Set the account id as a parameterMyFirstPDF.getParameters().put('accountId', someAccountId);// Create a new PDF document and add the contents of the page reference to itContentVersion cont = new ContentVersion();cont.Title = 'MyFirstPDF';cont.PathOnClient = 'MyFirstPDF.pdf';cont.VersionData = MyFirstPDF.getContentAsPDF();cont.Origin = 'H';insert cont; 

In this example, MyFirstPDF is a Visualforce page that renders the content of your PDF. You can use the <apex:page> tag and its various attributes and child tags to control the layout and appearance of your PDF. You can also use Apex code in your Visualforce page to retrieve data from your Salesforce org and populate the PDF with dynamic content.

Once you have generated your PDF document, you have a few options:

Generating a PDF on Button Click in Salesforce LWC

In your LWC, add a button that, when clicked, triggers an Apex method to generate the PDF from the Visualforce page.

<!-- LWC button --> <template> <lightning-button label="Generate PDF" onclick={generatePDF}></lightning-button></template>//ControllergeneratePDF() { generatePDFMethod({ recordId: this.recordId }) .then(result => { // handle success }) .catch(error => { // handle error });}

Apex Code to Generate the PDF: Use PageReference.getContentAsPDF() to fetch the content of the Visualforce page as PDF.

@AuraEnabledpublic static void generatePDFMethod(String recordId) { PageReference pdfPage = new PageReference('/apex/YourVisualforcePageName?id=' + recordId); Blob pdfBlob; pdfBlob = pdfPage.getContentAsPDF(); // Save, email or handle the PDF as needed}

Saving Generated PDF to Salesforce Files

Once you've generated the PDF blob, you can save it to Salesforce Files.

ContentVersion cont = new ContentVersion();cont.Title = 'GeneratedPDF';cont.PathOnClient = 'GeneratedPDF.pdf';cont.VersionData = pdfBlob;cont.Origin = 'H';insert cont;

Sending PDF as Email Attachment

The PDF blob can also be emailed as an attachment:

Send the PDF via email using the Messaging.SingleEmailMessage class.

//Send the emailMessaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();attach.setFileName('GeneratedPDF.pdf');attach.setBody(pdfBlob);Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();mail.setToAddresses(new String[] {'recipient@example.com'});mail.setSubject('Generated PDF from Salesforce LWC and Apex');mail.setHtmlBody('Please find attached the generated PDF.');mail.setFileAttachments(new Messaging.EmailFileAttachment[] {attach});Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

Integration with External Cloud Services:

For businesses with external cloud storage requirements, the generated PDF can be stored in services like AWS S3. Salesforce offers integration capabilities with AWS, allowing developers to push the generated PDF blob to an S3 bucket.

Learn more about Salesforce to AWS3 Integration

This Apex code can be used in a variety of contexts, including triggers, Apex Batch, or any other place where Apex is supported.

Fonts supported By Salesforce PDF Generation

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 firstfont-familyname listed is recommended.

Typefacefont-familyValues
Arial Unicode MSArial Unicode MS
Helveticasans-serif, SansSerif, Dialog
Timesserif Times
Couriermonospace Courier Monospaced DialogInput
  • These rules apply to server-side PDF rendering. Viewing pages in a web browser can have different results.
  • Text styled with a value not listed here uses Times. For example, if you use the word “Helvetica,” it renders as Times because that’s not a supported value for the Helvetica font. We recommend using “sans-serif”.
  • Arial Unicode MS is the only multibyte font available. It’s the only font that provides support for the extended character sets of languages that don’t use the Latin character set.
  • Arial Unicode MS doesn’t support bold or italic.
  • Web fonts aren’t supported when the page is rendered as a PDF file. You can use web fonts in your Visualforce pages when they’re rendered normally.

Custom Code vs Third-Party Apps for PDF generation

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

Salesforce PDF Generation Limits:

  • The maximum response size when creating a PDF file must be less than 15 MBbeforebeing rendered as a PDF file. This limit is the standard limit for all Visualforce requests.
  • The maximum file size for a generated PDF file is60 MB.
  • The maximum total size of all images included in a generated PDF is30 MB.
  • PDF rendering doesn’t support JavaScript-rendered content.
  • Rendering a Visualforce page as a PDF file is intended for pages designed and optimized for print.

Generate PDF Using Third-Party App:

Multiple apps 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 for salesforce pdf generation:

PDF Butler: PDF Butler is a tool for generating PDF documents from Salesforce data using custom templates. It offers a range of features, including the ability to create PDFs from records, related records, and custom objects, as well as support for formula fields and dynamic content. PDF Butler offers a paid version, with prices starting at $14 per user per month.

Easy PDF: Easy PDF is a tool for generating PDF documents from Salesforce data using custom templates. It offers a range of features, including the ability to create PDFs from records, related records, and custom objects, as well as support for formula fields and dynamic content.

Conga Composer: Conga Composer is a tool for generating PDF documents, as well as other types of documents and reports, from Salesforce data using custom templates. It offers a range of features, including the ability to create PDFs from records, related records, and custom objects, as well as support for formula fields and dynamic content.
Conga Composer prices start from $200/month ($20/user/month with 10 minimum users required).

S-Docs: SDocs is a tool for generating PDF documents from Salesforce data using custom templates. It offers a range of features, including the ability to create PDFs from records, related records, and custom objects, as well as support for formula fields and dynamic content.

SDocs pricing starts at $1500 per year for 1-10 users. This means that if you have 1-10 users who will be using the app, you will pay $1500 per year for the app.

Frequently Asked Questions (FAQs)

Can Salesforce generate PDF in Lightning?

PDF in salesforce can be generated easily without using any other app. That can work in Salesforce Lightning as well as Salesforce Classic.

What does it cost to generate PDF in Salesforce?

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. Using visualforce, it's completely free from monthly cost, it requires initial setup only.

Conclusion

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 therenderAsattribute 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.

Official document about visualforce

Learn more How to generate PDF for Salesforce Quote (No code)

Generate PDF in Salesforce For free in 2024 [Updated] - Arrify (5)

Kritik Garg

Freelance Salesforce Developer & Consultant

Kritik Garg is a highly skilled Salesforce developer and consultant with a proven track record of successfully completing projects of various sizes and complexities, from short-term assignments to long-term partnerships. He is the founder and CEO of Arrify, and is available to work on projects in the United States, United Kingdom, and Australia.
If you are looking for Salesforce Assistant, contact Kritik now.
Kritik has extensive experience working with various industries, including banking, healthcare, education, telecommunications, and manufacturing. He is an expert in Salesforce Sales, Service, and Marketing cloud, and is skilled in programming and developing various Salesforce features, such as APEX Programming, Lightning framework, VisualForce pages, Triggers, Workflows, Page Layouts, Roles, Profiles, Reports & Dashboards.

Generate PDF in Salesforce For free in 2024 [Updated] - Arrify (6)

Get Help with Custom PDF Generation!

Contact Form

Generate PDF in Salesforce For free in 2024 [Updated] - Arrify (2024)

FAQs

Can you generate a PDF from Salesforce? ›

There are two common ways that you can generate a PDF link in Salesforce. The first method is by using Visualforce pages, and the second is to use Lightning Components.

How do I generate a PDF on button click in Salesforce? ›

Generating a PDF on Button Click in Salesforce LWC

In your LWC, add a button that, when clicked, triggers an Apex method to generate the PDF from the Visualforce page. Apex Code to Generate the PDF: Use PageReference. getContentAsPDF() to fetch the content of the Visualforce page as PDF.

How do I create a PDF in lightning component? ›

Click the setup gear icon, and then select Edit Page. Drag the pdfGenerator component from the custom section to the page. Save the page. Click Generate PDF to create a PDF document.

How do I download a PDF from LWC? ›

You can achieve Using LWC how to generate pdf and download it by simply creating a "Lightning Web Component (LWC)" along with a "Visualforce page:. Then, you can render the Visualforce page by making an Apex call from the LWC. This approach enables you to generate and facilitate PDF downloads seamlessly.

Can Salesforce generate documents? ›

Salesforce users can generate business contracts, invoices, personalized letters, proposals, quotes, reports, and even forms within Salesforce. However, the types of documents they can generate will depend on what they've integrated Salesforce with.

How can I generate a PDF? ›

How to create PDF files: Open Acrobat and choose “Tools” > “Create PDF”. Select the file type you want to create a PDF from: single file, multiple files, scan, or other option. Click “Create” or “Next” depending on the file type.

How do I insert a PDF into Salesforce? ›

Click on "Salesforce Record Settings" from the Form connections page. Select the required value from the "PDF Attachments" dropdown. Click on "Save Record Settings."

What is lightning web component in Salesforce? ›

Lightning Web Components (LWC) are a user interface (UI) framework that Salesforce Developers use to create customized pages and functions on the Salesforce platform.

How do I embed a downloadable PDF? ›

To attach a file, go to Insert > Attach File in PDF. To embed a file, go to Insert > Embed File in PDF.

How do I export files and attachments from Salesforce? ›

Data Export feature of salesforce.

To use this feature you can navigate to Data Export then choose the files and attachments. Once expoert is completed, it will generate a link and email will be sent to you contain that link. By clicking this link you can download Files and Attachments.

Is it possible to automate PDF? ›

With PDF automation, you can run and manage actions and tasks to create, manipulate, generate, and extract content in your documents. Build workflows for content processing, invoice and report creation, data analysis, sales proposals, and more. Parse text, tables, images, and pages.

How do I Print a PDF in Salesforce? ›

Navigate to the Salesforce record that has the PDF you want to print. In the 'Notes & Attachments' section, click on the PDF file you want to print. This will open the PDF in a new tab or window in your web browser. In your web browser, go to the File menu and select 'Print.

Top Articles
Latest Posts
Article information

Author: Amb. Frankie Simonis

Last Updated:

Views: 6044

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Amb. Frankie Simonis

Birthday: 1998-02-19

Address: 64841 Delmar Isle, North Wiley, OR 74073

Phone: +17844167847676

Job: Forward IT Agent

Hobby: LARPing, Kitesurfing, Sewing, Digital arts, Sand art, Gardening, Dance

Introduction: My name is Amb. Frankie Simonis, I am a hilarious, enchanting, energetic, cooperative, innocent, cute, joyous person who loves writing and wants to share my knowledge and understanding with you.