Loading...

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.

    BlogImg 1 1

PDF Types:

BlogImg 2 1

BlogImg 3 1

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:

BlogImg 4 1

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:

BlogImg 5 1

VisualForce Code:

Final Output

BlogImg 6 1

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.

Related Articles
Dark Mode in Salesforce Enabling It and Creating Theme Ready Lightning Web Components with SLDS 2.0 1 1

With the Winter ’26 release, Salesforce introduced Dark Mode in Lightning Experience. Dark Mode has been introduced as a beta feature in Winter ’26, and at first it was available only for Starter Edition orgs. It is now rolling out further with Spring ’26 to Professional, Enterprise, and Developer editions. To use Dark Mode, Salesforce […]

Read More
Building a Reusable Popup Modal Architecture in Salesforce LWC 02 1

Modern Salesforce applications frequently rely on popup modals for confirmations, warnings, access control decisions, and destructive actions. However, building modal logic separately inside every Lightning Web Component often leads to duplicated code, inconsistent user experiences, and growing technical debt. This blog introduces a flexible popup modal architecture in Lightning Web Components (LWC) that centralizes modal […]

Read More
How to Add a Lookup Recipient in a Sign Template

This step-by-step guide will provide you with quick steps on how to add a lookup recipient inside a sign template in just a few easy steps. This process improves your eSignature for Salesforce workflow by pulling recipients directly from related records. Whether you rely on Salesforce digital signature features or any eSignature integration, adding lookup […]

Read More
Agentforce VS code

As Salesforce continues to move toward AI-assisted development, Agentforce is emerging as a powerful tool that helps developers interact with their org metadata, objects, and configurations using intelligent prompts. When combined with Visual Studio Code (VS Code) and the Salesforce CLI, Agentforce enables a faster, more context-aware way to explore and build on the Salesforce […]

Read More
How to Send Your First Document for eSignature

Sending documents digitally is now a core requirement for modern businesses. With eSignature for Salesforce and seamless eSignature integration, users can configure and send documents for signing directly from Salesforce, eliminating manual paperwork and speeding up approvals while keeping all data centralized and secure. In this guide, we will provide you with quick steps to […]

Read More
How to Allow Standard Salesforce Users to Add or Remove Queue Members Securely

Managing Salesforce queues is typically restricted to system administrators, which often creates operational slowdowns for teams that need faster control over their assignments. When non-admin users must rely on admins for routine queue updates, productivity drops, and simple changes turn into avoidable delays. In this blog, we’ll walk through a practical workaround to this limitation […]

Read More
Our Location worldwide
Indian Flag India
3rd Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203239658
United States of America Flag USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
United Kingdom Flag UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
Canada Canada
HIC Global Solutions INC
6D - 7398 Yonge St #1124 Thornhill, ON L4J 8J2 Canada +1(262) 310-7818