Dynamics NAV: printing external documents and merging PDF files

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:

PrintExternalDocs_01

The DotNet variables are as follows and all are RunOnClient = YES:

  • ProcessStartInfo: DotNet System.Diagnostics.ProcessStartInfo.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′
  • ProcessWindowStyle: DotNet System.Diagnostics.ProcessWindowStyle.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′
  • Process: DotNet System.Diagnostics.Process.’System, Version=4.0.0.0, 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:

MergePDF.png

 

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 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s