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
Orchestrator vs. Traditional Flows

Businesses use Salesforce automation to reduce manual work, improve efficiency, and automate repetitive business processes. Two commonly used automation approaches inside Salesforce are Traditional Flows and Flow Orchestrator. Traditional Flows are mainly used for simple automation tasks such as updating records, sending notifications, creating tasks, and automating business logic. Flow Orchestrator is designed for more […]

Read More
The Rise of Agentic Government_ What Salesforce’s 2026 Insights Mean for the Future of Public Sector AI

Government technology has often been seen as slower to evolve than the private sector. But Salesforce’s latest research challenges that idea in a big way. In fact, the new findings suggest that public sector organizations may now be moving faster than many businesses when it comes to adopting AI agents and preparing for a more […]

Read More
How To Use Email Service in APEX

Managing approvals, updates, and record changes directly from email can significantly improve efficiency within Salesforce workflows. Instead of logging in, navigating records, and manually updating fields, users can simply respond to emails and trigger automated updates using Email Service in APEX. This approach is especially useful for businesses leveraging Salesforce automation and looking to enhance […]

Read More
Design and Implementation of Salesforce Jira Task Integration 1 1

Businesses have been using Salesforce for CRM operations and Jira for Agile project tracking. However, without integration, teams manually update both systems, leading to data inconsistency and inefficiency.This mechanism establishes a real-time integration between Salesforce and Jira, allowing seamless synchronization of tasks and agile board statuses.  A custom Salesforce dashboard was developed that replicates Jira-style […]

Read More
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
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