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 "" 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!