Selecting an specific print to print a PDF

Hi everyone,

I’m trying to print a PDF that has been previously created in a folder. At the moment, I’m trying to do it from the server, running the RTC in the client, saving the PDF in the server, and trying to print like this:

  IF ISNULL(ProcessStartInfo) THEN
    ProcessStartInfo := ProcessStartInfo.ProcessStartInfo;
  ProcessStartInfo.UseShellExecute := TRUE;
  ProcessStartInfo.Verb := 'print';
  ProcessStartInfo.WindowStyle := ProcessWindowStyle.Hidden;
  //seleccionar impresora
  ProcessStartInfo.Arguments :='\\SRV-DC01\Etiqueta Expediciones';
  ProcessStartInfo.FileName := FileName;
  Process.Start(ProcessStartInfo);
  MESSAGE('Etiqueta enviada a impresora');

With this code, I’m just ablle to print from the default printer. “SRV-DC01” is the server name. Should I use the domain name? OR may be the IP? At the end, the development will be executed from the RTCs installed in different laptops, in the same network.

Thank you very much

Which version of NAV?

Remember that even when you run this code from the RTC Windows client, then the process is still executed on the NAV server by the service user. So it has to be a printer, that the service user has access to. And the same goes in regards to the folder with your PDF. It is relative to the server, not the client. And you need to upload any local files to the server from the client first, if the service user has no access.

I am using NAV 2018.

I found that issue you are talking, about he server side, for example, when I’m generating different XML files. The XMLport runs in server side, but I’ve solved that issue using a folder shared in the network.

My idea is to create the PDF files in the local machines, and call to the printer the way I’ve wrote in the code…

You have to remember the client does NOTHING! Think of it like this. If you have access to NAV using a webclient it still works, meaning that everything is done by the SERVER (The NAV servicetier). So the Servicetier user has to have the permission to see the printer and use the printer.

What .NET are you using? (ProcessStartInfo-variable). Because there are more than one you could use.

So, the printers should be defind and configured in the server side? Doesn’t mind how the are configured in the laptop with the RTC?

It simply means that the “user” that runs the Servicetier has to have permission access to the printer.

If you are running the servicetier as the account “Network Service” then you cannot print… Again it is NOT the user logged into NAV that does the printing. It is the Servietier…

Yes everything is done on the server. The RTC is really not much more than a web browser, it’s only your user interface. When you print a report then RTC communicates with your printer directly, but otherwise not.

Thank you both.

I must say that the NAV instance is running with a server account, called “administrator”. So, how can I reach the printer from the server? This is how the printers are declared on the server:

The printers declaired on the server is not necessary the same the “administrator” user can see. In your code you should use the \ip-adress\name or \server\printername in order to print.

There are many unknown variables in this, som it is hard to help you as we do not have the full view of your configuration.

It is possible to get it to work. But you could also go in another direction:

A faster solution could be to copy files to a specific folder - where a service picks up the file and prints it. There are several programs that can do that for you.

You could also create a powershell script. Like this one:

https://gregcaporale.wordpress.com/2012/01/18/powershell-to-print-files-automatically/

The main problem is that, I get the PDF file from a webService, and I need to print it. If I could “introduce” the PDF into a report, the problem will be solved with the report selection table, but I dpn’t know if it is possible to do that…

I’ve solved it using the PDFSharp library

  Printer := Printer.PdfFilePrinter(FileNameServer);
  Printer.DefaultPrinterName := 'Etiquetas Expediciones 2';
  Printer.AdobeReaderPath('C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe');
  Printer.Print();

Also must say that the printer configuration in our customer’s server wasn’t totally correct…

Now my issue is to rotate the PDF before sending to the printer, next challenge!