ArtifexSoftware / Ghostscript.NET

Ghostscript.NET - managed wrapper around the Ghostscript library (32-bit & 64-bit)
https://ghostscript.com
GNU Affero General Public License v3.0
391 stars 152 forks source link

Error: "'gsapi_init_with_args' is made -100" with long filename and Asian language #107

Open tu11950 opened 1 year ago

tu11950 commented 1 year ago

Hello, I'm using this function to "compress" PDF files. If the filename has Asian language (Japanese and Vietnamese) and the number of characters in filename is longer 15, the error "'gsapi_init_with_args' is made -100" will be appear.

Example:

My environment:

Please help me fix this. Thank you in advance.

This code with PDF files as above is not working and errors:

 try
            {
                GhostscriptVersionInfo gvi = GhostscriptVersionInfo.GetLastInstalledVersion();                

                string strFilePath = PDFFile.FullName;                               
                string strFileNameOnly = Path.GetFileNameWithoutExtension(PDFFile.Name);

                if (Array.Exists(iRenameIndex, x => x != 0) || strRenameReplace?.Length > 0)
                {
                    strFileNameOnly = Others.Rename(strFileNameOnly, iRenameIndex, strRenameReplace, strOutput, ".pdf");
                }                
                string strFullnameOutput = Path.Combine(strOutput, strFileNameOnly) + ".pdf";

                List<string> switches = new List<string>
                {                    
                    "-dQUIET",                    
                    "-dBATCH",
                    "-dNOPAUSE",                    
                    "-sDEVICE=pdfwrite",                    
                    "-dPDFSETTINGS =/default",                    
                    "-sOutputFile=" + strFullnameOutput,                    
                    strFilePath,
                };               

                using (GhostscriptProcessor gsProc = new GhostscriptProcessor())
                {
                    try
                    {                        
                        gsProc.StartProcessing(switches.ToArray(),null);                        
                        isDone = true;
                    }
                    catch (Exception ex)
                    {
                    MessageBox.Show(ex.Message);
                    isDone = false;
                    }                    
                }
            }
litao198610 commented 1 year ago

I had the same problem,when I printpdf on win11 using Ghostscript.NET v1.2.3。When printing a pdf file, multiple tasks appeared in the printer queue.the cod is following,The code is shown below: public static void PrintReceipt(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) { throw new Exception(ex.Message); } }

My environment:

Windows 11 Chinese 64-bit Ghostscript version: 10.0.0 64-bit Ghostscript.NET v1.2.3 (latest)