📄 PDF Generator Button for Salesforce LWC
Generate professional PDF documents from any Salesforce record with a single click, automatically save them as Salesforce Files, and maintain a complete PDF history.
📖 Project Overview
PDF Generator Button is a reusable Lightning Web Component that enables users to generate PDF documents directly from Salesforce record pages.
The component renders a configurable Visualforce page as a PDF, stores it as a Salesforce File (ContentVersion), automatically links it back to the source record, and displays recently generated PDFs for quick access.
Designed for enterprise Salesforce applications, the solution works across standard and custom objects without requiring object-specific code.
✨ Key Features
| Feature | Description |
|---|---|
| One-Click PDF Generation | Generate PDFs directly from Lightning record pages. |
| Reusable Across Objects | Supports Account, Contact, Opportunity and custom objects. |
| Automatic File Naming | Creates descriptive file names automatically or allows a custom name. |
| Salesforce Files Integration | Creates ContentVersion and ContentDocumentLink records automatically. |
| PDF History | Displays the latest generated PDFs for each record. |
| Download Support | Open or download generated PDFs directly. |
| Toast Notifications | Instant success and error feedback. |
| Configurable Template | Use any Visualforce page as the PDF template. |
| Permission Set Included | Easy deployment using the included permission set. |
🏗 Architecture
📁 Project Structure
force-app/main/default
│
├── lwc
│ └── pdfGeneratorButton
│ ├── pdfGeneratorButton.html
│ ├── pdfGeneratorButton.js
│ ├── pdfGeneratorButton.css
│ └── pdfGeneratorButton.js-meta.xml
│
├── classes
│ ├── PdfGeneratorController.cls
│ ├── PdfGeneratorControllerTest.cls
│ ├── RecordPdfPageController.cls
│ └── RecordPdfPageControllerTest.cls
│
├── pages
│ └── RecordPdfPage.page
│
└── permissionsets
└── PdfGenerator.permissionset-meta.xml
⚙️ Lightning App Builder Configuration
| Property | Default | Description |
|---|---|---|
| buttonLabel | Generate PDF | Custom label displayed on the button. |
| vfPageName | RecordPdfPage | Visualforce page used to generate the PDF. |
| pdfFileName | Auto Generated | Optional static PDF filename. |
🔄 PDF Generation Flow
Open Record
│
▼
Click "Generate PDF"
│
▼
Visualforce Page Rendered
│
▼
PDF Created
│
▼
ContentVersion Created
│
▼
ContentDocument Linked
│
▼
PDF History Refreshed
📂 Automatic File Naming
_ _ .pdf Example: Account_001XXXXXXXXXXXX_2026-06-28.pdf
📜 PDF History
- Displays the latest 20 generated PDF files.
- Shows files linked to the current record.
- One-click preview and download.
- Automatically refreshes after generating a new PDF.
🧩 Custom PDF Templates
The component supports any Visualforce page as a PDF template. Simply specify the Visualforce page API name in the component configuration to generate customized invoices, quotations, certificates, reports, contracts, or business documents.
🔐 Security Features
- Uses with sharing Apex controllers.
- Respects Salesforce record-level security.
- Stores documents using native Salesforce Files.
- Supports controlled rollout through the included permission set.
- Works with standard Salesforce authentication.
🚀 Deployment
sf org login web --alias myOrg sf project deploy start \ --source-dir force-app \ --target-org myOrg sf org assign permset \ --name PdfGenerator sf apex run test \ --class-names PdfGeneratorControllerTest,RecordPdfPageControllerTest
🎯 Business Use Cases
- Invoice Generation
- Sales Quotations
- Customer Agreements
- Booking Confirmations
- Service Reports
- Purchase Orders
- Certificates
- Inspection Reports
- Healthcare Documents
- Custom Business Forms
📌 Conclusion
The PDF Generator Button is a reusable Salesforce Lightning Web Component that streamlines PDF creation directly from Lightning record pages. By combining Lightning Web Components, Apex, Visualforce, and Salesforce Files, it provides a simple, secure, and scalable solution for generating and managing business documents across any Salesforce object.


