Salesforce users and developers often need to create PDFs, Word documents, or PowerPoint decks directly from record data. Commercial solutions usually charge per-user, per-month fees that can add up quickly. SalesforceDocGen is an open-source, 100% server-side package that removes those costs while providing a full feature set: template management, bulk generation, flow integration, background PDF rendering, rich text handling, and even multi-signer electronic signatures.
What SalesforceDocGen Offers
- Free & Open-Source – MIT licensed, no hidden costs.
- Native Apex Engine – All processing happens on the server; no client-side templating libraries are required.
- Multiple Output Formats – DOCX, PPTX, PDF.
- Rich Text & Images – Embedded images from rich text fields, HTML support.
- Bulk Generation – Generate documents for thousands of records in a single batch.
- Flow Integration – Two invocable actions for record-level and bulk generation.
- Multi-Signer e-Signatures – Role-based signing with secure links.
Key Features at a Glance
| Feature | Description |
|---|---|
| Template Manager | Upload, edit, version, and share .docx/.pptx templates. Visual query builder eliminates SOQL knowledge for most users. |
| Record Page Generator | Lightning Web Component (docGenRunner) drops into any record page to generate documents instantly. |
| Bulk Document Generation | Filter records with SOQL WHERE clauses; real-time progress tracking; Apex batch background processing. |
| Flow Actions | DocGenFlowAction (single record) and DocGenBulkFlowAction (bulk/streaming). |
| PDF Rendering | Client-side preview + html2pdf conversion or server-side Named Credential loopback with retry logic. |
| Electronic Signatures | Role-based signing, secure token links, Visualforce portal, PNG injection, SHA-256 audit trail. |
Installation & Setup
-
Install the Subscriber Package
sf package install --package 04tdL000000Or6PQAS --wait 10 --installation-key-bypass - Assign Permission Sets –
DocGen Admin,DocGen User, and (if using signatures)DocGen Guest Signature. - Add the Generator to Record Pages – Drag the
docGenRunnerLightning Web Component onto any record page via App Builder. - Configure PDF Engine – Run the 3-step wizard in the DocGen Setup tab: create an External Client App, provision credentials (Auth Provider, External Credential, Named Credential), authenticate, and grant access to permission sets.
- Optional Signature Configuration – Create a Salesforce Site for public signature links, enable guest access for relevant Visualforce pages, and enter the site URL in the DocGen Setup wizard.
Using the App in Lightning Pages
- The
docGenRunnercomponent appears as a button on any record page. - Users can select from available templates filtered to that object.
- One-click generation produces DOCX with automatic PDF rendition; generated files attach to the record's Files related list.
- For bulk operations, navigate to the DocGen Bulk Gen tab and set SOQL filters.
Bulk Generation & Flow Integration
| Use Case | Invocable Action |
|---|---|
| Single Record | DocGenFlowAction – inputs: templateId, recordId; outputs: contentDocumentId, errorMessage. |
| Bulk/Batch | DocGenBulkFlowAction – inputs: templateId, optional queryCondition; outputs: jobId, errorMessage. |
These actions can be embedded in any Flow, making document generation a first-class citizen of your automation.
PDF Rendering Options
Client-Side
A VF iframe receives the DOCX via postMessage. docx-preview.js renders with full formatting; html2pdf.js converts to PDF and saves back as a ContentVersion.
Server-Side (Bulk & Flow)
Named Credential loopback calls Salesforce's Connect REST API (/services/data/v63.0/connect/files/{id}/rendition?type=PDF). Built-in retry handles 202 Accepted latency.
Electronic Signatures
- Zero-Cost, Multi-Signer – Define roles (Buyer, Seller, Witness) per template.
- Secure Token Links – Each signer receives a unique URL (
https://your-site.salesforce-sites.com/apex/DocGenSignature?token=<secure_token>). - Visualforce Signing Portal – Mobile-friendly capture with live preview; no Experience Cloud configuration required.
- OpenXML Stamping & SHA-256 Audit Trail – Signatures are PNGs injected into DOCX placeholders before PDF conversion, and each signed PDF is hashed for immutable audit.
Template Tag Syntax
| Tag | Purpose | Example |
|---|---|---|
{FieldName} |
Simple field merge | {Account.Industry} |
{#ChildList}...{/ChildList} |
Loop over child records | {#Contacts}{FirstName} {LastName}{/Contacts} |
{%ImageField} |
Inject image (default size) | {%Company_Logo__c} |
{#Signature_RoleName} |
Multi-signer placeholder | {#Signature_Buyer} |
Tags are placed directly in the .docx or .pptx template files; the engine expands them server-side.
Architecture Overview
- Template Decompression – ZIP decompression via Salesforce Compression API.
- XML Pre-processing – Merge split text runs, normalize tags across formatting boundaries.
- Server-Side Tag Processing – Simple substitution, loop expansion, conditional rendering, image injection, rich text handling.
- Recompression & Storage – Save as ContentVersion.
- PDF Rendition – Either client-side conversion or server-side Named Credential loopback.
- Signature Flow – Secure token validation → DOCX preview → PNG capture → stamping → PDF upload.
Contributing and Licensing
The project is under the MIT license; contributions are welcome via GitHub issues or pull requests. Repository structure: force-app/main/default/ contains Apex classes, LWC components, Visualforce pages, permission sets, and static resources. Documentation can be found in the repository's README.md, INSTALL.md, and LICENSE files.