Generate PDF in Salesforce without any app (2022)

Kritik GargKritik Garg
3 min read

Source of post: Generate PDF in Salesforce without any app

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.

Steps to generate pdf in Salesforce

  • Create a Static Resource
  • Create a VF page
  • Create a button to Generate PDF

What you need before start

  • Your Company Logo
  • Working Salesforce Org

Let’s Start to generating pdf in Salesforce

To create a static resource:

  1. From Setup, enter Static Resources in the Quick Find box, then select Static Resources.
  2. Click New.
  3. In the Name text box, enter the text “companyLogo”.
  4. Next to the File text box, click Browse to navigate to a local copy of your Company Logo.
  5. Set the Cache Control to public.
  6. Click Save.

Create a Detail Page Button on Account to generate PDF:

To Create a Button on Account

  1. From Setup, click Object Manager, then click Account.
  2. Click Buttons, Links, and Actions, then click New Button or Link.
  3. Name the button "Generate PDF".
  4. Select Detail Page Button.
  5. Set Content Source “Visualforce Page
  6. Select content “MyFirstPDF
  7. Click Save, then click OK. Now add it to the Account page layout.
  8. Click Page Layouts, then click Account Layout.
  9. From the Buttons category in the palette, drag **Generate PDF**" into the Custom Buttons area on the page layout.
  10. Click Save. OK! Now let’s test it.
  11. From the App Launcher, find and select Sales, then click the Accounts tab.
  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 select Generate PDF. The browser opens a new window or tab that shows you the PDF.

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

Official document about visualforce

0
Subscribe to my newsletter

Read articles from Kritik Garg directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kritik Garg
Kritik Garg