Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tu11950 opened this issue Dec 29, 2022 · 1 comment

Comments

@tu11950
Copy link

tu11950 commented Dec 29, 2022

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;
                    }                    
                }
            }
@litao198610
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants