web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Challenges with Merging Multiple PDFs in Dynamics 365 Business Central Using PDF-lib

(4) ShareShare
ReportReport
Posted on by 2,100
Hi Community,
We are currently working on a solution to merge different financial reports into a single PDF in Dynamics 365 Business Central, but we are encountering some challenges and would appreciate your input.

Our approach involves using the JavaScript library PDF-lib along with a controller add-in to handle the merging process. The functionality works when merging 2 or sometimes 3 financial reports, but we face issues when trying to merge 3 or more PDFs. In these cases, the merge operation fails, and the file is not downloaded. Note : No error message appears, and the response event "DownloadPDF" from JavaScript is not triggered.

Additionally, we’ve observed that the merging process is inconsistent. For example, sometimes two PDFs merge successfully, while other times the same two files fail to merge—even if they were successfully merged just moments ago.
We are looking for a solution that does not rely on third-party APIs or Power Automate or Azure. If anyone has encountered similar issues or can suggest a more stable approach to merging PDFs in Business Central, your insights would be greatly appreciated.

We are referencing the "Merge-PDF-Business-Central" repository by "gonzaloriosley" to merge PDFs using JavaScript in Business Central.

Below is our slightly modified code for the "MergePDF" Codeunit:

codeunit 50150 MergePDF
{
    procedure AddReportToMerge(Ins: InStream);
    var
        StreamOut: OutStream;
        Parameters: Text;
        Convert: Codeunit "Base64 Convert";
    begin
        Clear(JObjectPDFToMerge);
        JObjectPDFToMerge.Add('pdf', Convert.ToBase64(Ins));
        JArrayPDFToMerge.Add(JObjectPDFToMerge);
    end;

    procedure AddBase64pdf(base64pdf: text);
    begin
        Clear(JObjectPDFToMerge);
        JObjectPDFToMerge.Add('pdf', base64pdf);
        JArrayPDFToMerge.Add(JObjectPDFToMerge);
    end;

    procedure ClearPDF();
    begin
        Clear(JArrayPDFToMerge);
    end; 

    procedure GetJArray() JArrayPDF: JsonArray;
    begin
        JArrayPDF := JArrayPDFToMerge;
        fileCount := JArrayPDF.Count;
    end;

    var
        JObjectPDFToMerge: JsonObject;
        JArrayPDFToMerge: JsonArray;
        JObjectPDF: JsonObject;
        fileCount: Integer;
}


Any help or advice would be greatly appreciated!
I have the same question (0)
  • Gerardo Rentería García Profile Picture
    25,157 Most Valuable Professional on at
  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at
    Recently, I have run into same issue while using the JavaScript Library in BC, I have to use Azure Functions Approach as the standard approach was very slow and it has limitations on the file size.
     
    Use the Azure Function Service from the link
     
  • Suggested answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at
  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at
    You can try this one, I have developed and my side its working fine.
     
     
     
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,275 Super User 2025 Season 2 on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans