How to Merge PDF Files within Business Central
Recently, our team was tasked with a request to merge PDF files from within Microsoft Dynamics 365 Business Central. The client wanted to combine sales documents, Terms and Conditions, and Warranty terms into a single PDF document. Since this client sends many sales invoices and invoices to their customers, the concern was that if this information wasn’t sent together, customers might overlook it.
Since using Dynamics Link Libraries (DLLs) or .NET functions is not supported in Business Central’s SaaS environment, we were forced to consider other alternatives.
Finding the right solution
Initially, we thought the perfect solution was already available in Business Central via the Document Sending Profiles and the “Combine” option. However, I evaluated this feature and attempted to write logic to attach the Terms and Conditions pdf to the Sales Order report.
Unfortunately, this didn’t work. The out-of-the-box Business Central PDF feature is simply setting a document number filter and running the sales report that creates one pdf with all orders via the filter. It doesn’t string PDFs of each document.
While the initial thought was to leverage the Document Sending Profiles and the “Combine” option already available in Business Central, it turned out that this feature merely applies a document number filter and generates a PDF with all orders via the filter rather than stringing together PDFs of each document.
Further research led us to a post by Gonzalo Rios Ley that recommends using a control add-in from the PDF-LIB JavaScript library to build a JSON Array with base64 versions of each pdf and then merge them into a single PDF within Business Central. This solution doesn’t require any software installation or external DLL files, and it is compatible with both Business Central SaaS and On-Premises.
The solution provides some basic functions, including the Report ID and a Record Ref variable or a base64 string of the PDF. Visit Rios Ley’s Github for code examples and to learn more.
Usage tips to keep in mind
If you decide to tackle this on your own, however, there are a couple of important points to note:
- The Print button won’t display the report on the monitor since the PDF it generates is downloaded to the Download folder. Consider displaying a message for the user to check their download folder to access the document.
- The control add-in logic must be on the Page with the Print w/TnC action button. Calling the download logic from a custom codeunit will not work. See the example provided by Gonzales Rios Ley.
Looking for Business Central support?
If you need help with Business Central, ArcherPoint offers 24×7 support with several plans, including a pay-as-you-go plan. Contact ArcherPoint to find out more about our support options.