Dynamics 365 Business Central: merging PDFs online with an Azure Function.

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:

Considerations

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:

  • From Business Central (or from your source of the PDF files), save the report’s PDF files to an Azure Blob Storage container.
  • Pass to the Azure Function a JSON containing a list of files that need to be merged.
  • In the Azure Function code, retrieve the files from the Azure Blob Storage container, merge them and save the output file (result of the merge) to the Azure Blob Storage container again.
  • Download the file from the container.

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/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
March 2025
MTWTFSS
      1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       
« Feb   Apr »
Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...