Skip to content

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

Open
@tu11950

Description

@tu11950

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:

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

  • I also use the PDF to TIFF conversion using Ghostscript.NET. When using this feature with PDF files as above, there is no problem. Code below with PDF files as above is OK:

       var InputStream = File.Open(strFilePath, FileMode.Open);
              using (var rasterizer = new GhostscriptRasterizer())
              {                    
                  rasterizer.Open(InputStream,gvi,false);
                  int PdfPages = rasterizer.PageCount;
                  for (int pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++)
                  {
                      string outputPNGPath = Path.Combine(strOutput, strFileNameOnly + pageNumber.ToString() + ".tiff");
                      Image pdf2PNG = rasterizer.GetPage(iDPI, pageNumber);
                      pdf2PNG.Save(outputPNGPath, ImageFormat.Tiff);
                  }
                  rasterizer.Close();
              }
              InputStream.Dispose(); 
    

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.

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;
                    }                    
                }
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions