Some days ago on an internal forum (Yammer) someone posted the following request:
Is it possible in Dynamics 365 Business Central to combine multiple reports into a single PDF file?
This is a feature that Microsoft is considering for the next waves, but at the moment there’s not a native way to do that.
On that post, I promised to share a solution that I’m currently using and here it is.
The solution is an Azure Function (.NET Isolated with free and open source library) that permits you to pass a JSON array of documents to merge (Base64 format) and gives you as output a merged PDF document (as Base64).
Full source of the Azure Function is available on my GitHub here.
You can call the Azure Function directly from AL code in Dynamics 365 Business Central by using a POST request like the following:
POST YOURFUNCTIONURL/api/MergePDF
Content-Type: application/json
[
{
"Name": "Invoice102404.pdf",
"Base64Content": "BASE64CONTENT_DOCUMENT_1"
},
{
"Name": "Invoice102405.pdf",
"Base64Content": "BASE64CONTENT_DOCUMENT_2"
}
]
where Name is the name of the report and Base64Content is the Base64 content of the report PDF stream.
The output of the Azure Function will be a Base64 string containing the content of the merge of the PDF files you have passed as input:
The demo here sends to the Azure Functions two sales invoices from Business Central:
and the output is a single file containing the merge of the two documents:
The Azure Functions works fully online and in-memory on the App Service and permits you to merge different PDF files into one.
If you need to merge a really big number of files and/or files with a very big size, it’s absolutely better to refactor the code to use the Azure Blob Storage as repository. So:
The code in the Azure Function is provided “as is” and can be absolutely improved.
If you want, feel free to add pull requests to the repo.
Original Post https://demiliani.com/2025/02/04/dynamics-365-business-central-merging-pdfs-online-with-an-azure-function/