These are old topics and someone has written on a solution for this in the past, but after some forum questions received today I think that a quick recap could be interesting.
Question 1: how to print external documents directly from NAV
There are scenarios where you need to print directly from NAV also external documents (like PDF, Word files or other things).
For this task, in my personal library I use a solution based on DotNet variables and the System.Diagnostics.Process class (that provides access to local and remote processes and enables you to start and stop local system processes). If I remember correctly, the idea from this comes from my friend Waldo (so credits to him 🙂 ).
To solve this task, I have a C/AL function called PrintExternalDocument that receives a path of a file and calls a TryFunction PrintDocument for handling the printing. The C/AL code is as follows:
The DotNet variables are as follows and all are RunOnClient = YES:
- ProcessStartInfo: DotNet System.Diagnostics.ProcessStartInfo.’System, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b77a5c561934e089′
- ProcessWindowStyle: DotNet System.Diagnostics.ProcessWindowStyle.’System, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b77a5c561934e089′
- Process: DotNet System.Diagnostics.Process.’System, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089′
The key here is the verb Print passed to the ProcessStartInfo class (a .NET class that specifies a set of values that are used when you start a process). With that, the OS will use the process asociated to this document type to print the document.
Question 2: How to merge two PDF files into a single one
There are programs like BullZip (one of my favourite PDF printers to use with NAV) that have these functions available in the commercial version.
Here I post an old solution that uses a free and open source program called PDFMerge (available on GitHub here). Also for this task we need the usage of DotNet variables and the System.Diagnostics.Process class.
After installing PDFMerge, you can create a function called MergePDF that receives as input parameters the files to merge and the output PDF file.
Here is the C/AL code:
I’m sure that there are other solutions for these tasks, but this works 🙂
P.S. As you can see, these functions are not Dynamics 365 Business Central ready 🙂