Ghostscript.Net doesn't working in Windows Server 2012 R2

1.3k views Asked by At

I am using Ghostscript.NET in my Project to print Pdf files across Network. Locally works fine, using Windows 10, version 64-Bit and Ghostscript Driver to 32-Bit (Ghostscript 9.22 for Windows 32-Bit) downloaded from https://www.ghostscript.com/download/gsdnld.html. The motivation to install 32-Bit version is the exception,

Ghostscript.NET.GhostscriptLibraryNotInstalledException: This managed library is running under 32-Bit process and requires 32-Bit Ghostscript native library installation on this machine! To download proper Ghostscript native library please visit: http://www.ghostscript.com/download/gsdnld.html

, which occurs in my application log when using Ghostscript 64-Bit Driver.

The target Operation System where I published my application is Windows Server 2012 R2. Using same Ghostscript Driver (Ghostscript 9.22 for Windows 32-Bit), print command loops indefinitely, without response to my application.

For the purpose, I disabled the Firewall and Antivirus to eliminate possibilities of them being loop cause.

My application reads pdf file from disk and sends it to Network Printer using Ghostscript. For simulating the process I connect to client machine remotely using TeamViewer. So, I call a REST Web Service from this machine, which saves the file to disk and uses Ghostscript to print the document in a Network Printer.

try
                {
                    var task = Task.Run(() =>
                    {
                        using (GhostscriptProcessor processor = new GhostscriptProcessor(GhostscriptVersionInfo.GetLastInstalledVersion(), true))
                        {
                            List<string> switches = new List<string>();
                            switches.Add("-empty");
                            switches.Add("-dPrinted");
                            switches.Add("-dBATCH");
                            switches.Add("-dNOPAUSE");
                            switches.Add("-dNOSAFER");
                            switches.Add("-dPDFFitPage");
                            switches.Add("-dNumCopies=" + numCopias);
                            switches.Add("-sDEVICE=mswinpr2");
                            switches.Add("-sOutputFile=%printer%" + "\\\\" + printerIP + "\\" + printerNAME);
                            switches.Add("-f");
                            switches.Add(inputFile);

                            processor.StartProcessing(switches.ToArray(), null);
                        }
                    });

                    if (!task.Wait(TimeSpan.FromSeconds(Int32.Parse(ConfigurationManager.AppSettings["MAX_PRINTER_DELAY"]))))
                    {
                        Log.Info(String.Format("A impressão do arquivo ({0}) ({1}) foi encerrada porque ultrapassou MAX_PRINTER_DELAY = {2}!", inputFile, printerNAME, ConfigurationManager.AppSettings["MAX_PRINTER_DELAY"]));
                    }

                }
                catch (GhostscriptLibraryNotInstalledException e)
                {
                    Log.Info("O GhostScript não está instalado.");
                    Log.Error(e);
                }
                catch (GhostscriptException e)
                {
                    Log.Info("O GhostScript apresentou erro.");
                    Log.Error(e);
                }
                catch (Exception exception)
                {
                    Log.Error(exception);
                }

I am using Ghostscript.NET version 1.2.1.0.

Can someone help me?

1

There are 1 answers

0
Tarcisio M. On

The Microsoft Windows Security Architecture seems not allows Asp Net API to access COM devices as a Printer directly, without the use of Impersonation. Through using Third Party libraries and a local printer connected to Computer with a higher level of intranet user as IIS User, the system printed the file. The best answer ( source code implementation, in my opinion, clearly and reusable without great "refactory effort" at the point of my need ) was obtained developing a Windows Service Program (installed as Admin user which have access to COM devices) that watches a directory and sends your content to the printer using another program as Adobe Reader. The target Printer for my real scenario was an IP Printer, not a local Printer.