Skip to main content
Is anyone done this earlier?  as we cannot merge 2 pdf files into 1 pdf file with apex, i would like to use any third party open source javascript libraries , what is the best approach or options to do this kind of requirement, any suggestions are appreciated , TIA
7 réponses
  1. 27 juil., 10:12

    pdf-lib is what most people use for this. Upload it as a static resource, load it in an LWC with loadScript, pull the files' base64 VersionData from Apex, merge in the browser, then save the result back as a new ContentVersion.

    Main reason to do it client-side rather than Apex: you skip the 6MB/12MB heap limit, so large files still work.

     

    const merged = await PDFLib.PDFDocument.create();for (const b64 of base64Files) {  const doc = await PDFLib.PDFDocument.load(b64);  const pages = await merged.copyPages(doc, doc.getPageIndices());  pages.forEach(p => merged.addPage(p));}const out = await merged.saveAsBase64();

    If the library misbehaves under Lightning Web Security, the usual workaround is running pdf-lib in a Visualforce page inside an iframe and passing data with postMessage.

    If you'd rather not host the library, Api2Pdf and Adobe PDF Services both do merge via callout — but the files leave your org, which rules them out for most healthcare/finance work. 

     

    https://hicglobalsolutions.com/blog/how-to-merge-and-brand-pdf-files-in-salesforce-using-lwc-visualforce-pdf-lib/

0/9000