gsapi_init_with_args' is made -100 with long and Asian language in filename

91 Views Asked by At

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 appear.

Example:

  • Input Filename: "こんにちは、私の名前は.pdf" or "Xin chào, tôi tên là. Xin chào, tôi tên là.pdf"
  • Output Filename: "こんにち.p" or "Xin cháo, tôi tơn lá". They're without extension in filename, zero size and incorrect filename.
  • Expected Filename: "こんにちは、私の名前は.pdf" or "Xin chào, tôi tên là. Xin chào, tôi tên là.pdf" with smaller size.

If the filename has Asian language (Japanese and Vietnamese) and the number of characters in filename is shorter 15, it's OK to use.

My environment:

  • Windows 11 English US 64-bit (Locale in Settings is Japanese)
  • Ghostscript version: 9.55.0 32-bit
  • Ghostscript.NET v1.2.3 (latest) Please help me fix this. Thank you in advance.
try
            {
                string strFilePath = PDFFile.FullName;
                string strFileNameOnly = Path.GetFileNameWithoutExtension(PDFFile.Name);               
                
                GhostscriptVersionInfo gvi = GhostscriptVersionInfo.GetLastInstalledVersion();
                string strFullnameOutput = Path.Combine(strOutput, strFileNameOnly) + ".pdf";
List<string> switches = new List<string>
                {
                    "-empty",
                    "-dQUIET",
                    "-dSAFER",
                    "-dBATCH",
                    "-dNOPAUSE",
                    "-dNOPROMPT",
                    "-sDEVICE=pdfwrite",
                    "-dCompatibilityLevel=2.0",
                    "-dPDFSETTINGS =/default", 
                    "-sOutputFile=" + strFullnameOutput,
                    //"-dPrinted=false",                    
                    "-c",
                    "-f",
                    strFilePath,
                };                

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

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                isDone = false;
            }

I've tried to change another computer but same result.

0

There are 0 best solutions below