ArtifexSoftware / Ghostscript.NET

Ghostscript.NET - managed wrapper around the Ghostscript library (32-bit & 64-bit). Tested with Ghostscript versions < 10.
https://ghostscript.com
GNU Affero General Public License v3.0
403 stars 155 forks source link

Module could not be loaded #111

Open litao198610 opened 1 year ago

litao198610 commented 1 year ago

when i use ghostscript.net to print pdf file,the system throw exception "Module could not be loaded",I downloaded gsdll to a local folder,Do you know what caused it? the code is following: public static void Printpdf(string pdfFilePath,string printerName) { try { var path = ""; if (Environment.Is64BitOperatingSystem) { path = Path.Combine(AppContext.BaseDirectory, "GSDll/gsdll64.dll"); } else { path = Path.Combine(AppContext.BaseDirectory, "GSDll/gsdll32.dll"); } var gvi = new GhostscriptVersionInfo(path); Ghostscript.NET.Processor.GhostscriptProcessor processor = new Ghostscript.NET.Processor.GhostscriptProcessor(gvi, true); var switches = new List(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNoCancel"); switches.Add("-dNOPROMPT"); switches.Add("-dNOPAGEPROMPT"); switches.Add("-dPDFFitPage"); switches.Add("-dQueryUser=3"); switches.Add("-dNumCopies=1"); switches.Add("-dSubsetFonts=false"); switches.Add("-sDEVICE=mswinpr2"); switches.Add("-f"); switches.Add(Convert.ToString("-sOutputFile=%printer%") + printerName); switches.Add(pdfFilePath); processor.StartProcessing(switches.ToArray(), null); } catch (Exception ex) { if (System.IO.File.Exists(pdfFilePath)) { System.IO.File.Delete(pdfFilePath); } throw new Exception(ex.Message,ex); } }

ab78908 commented 1 year ago

I have seen this error when gsdll64.dll from ghostscript native library installation got somehow corrupted. LoadLibrary Win32 function was returning error 998 ERROR_NOACCESS. Overwriting the file with fresh copy resolved the issue.