Salesforce developers frequently encounter document automation requirements that go beyond standard Apex-based PDF generation. From merging multiple ContentVersion files to dynamically applying branding like watermarks and headers, traditional server-side approaches often hit Salesforce heap size limits (6MB/12MB), creating performance and scalability challenges. This guide presents a heap-limit-safe PDF merging architecture in Salesforce using Lightning Web Components (LWC), Visualforce, and the powerful pdf-lib JavaScript library.
By shifting heavy PDF processing to the browser, this approach enables large file handling, dynamic document branding (Draft/Final modes), and multi-document merging without compromising platform performance.
If you’re building enterprise-grade Salesforce document automation, this architecture provides a scalable, modern, and production-ready solution.
Key Functionalities
The tool provides a dual-engine approach to document management:
Dynamic Branding (Single PDF): Instantly applies version-specific branding, such as a 45° rotated red “DRAFT” watermark or a blue “FINAL PRESENTATION” header label.
Sequence Synthesis (Multi-PDF Merge): Allows users to select multiple documents from a record list and merge them into a single, cohesive PDF file.
LWC as the Orchestration Layer for Secure PDF Selection & Processing
The Pdfmerger LWC acts as the control center:
- Data Table Integration: Uses lightning-datatable to display available ContentVersion records.
- Selection Logic: Captures selected record IDs and prepares them for processing.
- URL Orchestration: Securely passes the joined IDs and UI instructions (e.g., showForm=true) to the processing engine via URL parameters.
PDF Types:
The Selection Layer (LWC)
The Pdfmerger LWC acts as the control center:
- Data Table Integration: Uses lightning-datatable to display available ContentVersion records.
- Selection Logic: Captures selected record IDs and prepares them for processing.
- URL Orchestration: Securely passes the joined IDs and UI instructions (e.g., showForm=true) to the processing engine via URL parameters.
LWC CODE:
CSS:
JavaScript:
Apex Code:
Static Resources:
Visualforce Processing Engine: Client-Side PDF Merging Without Apex Heap Limits
The Visualforce page serves as a secure container for JavaScript-based PDF modification:
- Client-Side Processing: Converts Base64 file strings from Apex into ArrayBuffers for manipulation.
- Memory Efficiency: By performing merging in the browser, the system avoids the 6MB/12MB Apex heap limit, allowing for larger file handling.
Enterprise UX Enhancements: Shimmer Loaders, Micro-Interactions & Responsive Modals
To provide a premium enterprise experience, the tool incorporates modern design elements:
Shimmer Loading Effect: A skeleton-style animated loader that provides visual feedback while files are being fetched from the server.
Micro-Interactions (Dynamic Dot): A custom black “Dot” that smoothly expands to display the currently selected document version (“Active” state) upon hover.
Responsive Modals: Uses a flexible popup architecture that adapts to different screen sizes, ensuring accessibility on mobile devices.
VisualForce Page UI:
VisualForce Code:
Final Output
Watch Live Demo – https://drive.google.com/file/d/1CSGkh3BrgfY-6qk2lApmBhiTWzOLHNd8/view?usp=sharing
Conclusion
Modern Salesforce applications demand more than basic document generation; they require scalable, performant, and user-friendly automation frameworks. By separating the orchestration layer (LWC) from the processing engine (Visualforce + pdf-lib), this architecture eliminates Apex heap size limitations while delivering high-performance PDF merging and dynamic branding directly in the browser.
The result is a production-ready Salesforce document automation solution that is scalable, maintainable, and enterprise-grade. Whether you’re handling bulk PDF merging, real-time watermarking, or branded presentation exports, this approach ensures consistent performance without compromising user experience.
At HIC Global Solutions, we specialize in building advanced Salesforce development architectures that overcome platform constraints while maintaining security, scalability, and clean design patterns.
If your organization is exploring custom document automation, Salesforce integration, or performance-optimized Lightning Web Component solutions, our Salesforce Services team can help design and implement enterprise-ready solutions tailored to your business needs.
No Data Found.