Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

a -100 from gsapi_init_with_args

Help
Gill
2012-03-19
2013-03-21
  • Gill
    Gill
    2012-03-19

    I have implemented the ghost script. Now I am executing the code on Windows 2008 server R2 (64 bit OS) and getting following error

    "Ghostscript failed with error code -100" when the following is called

    gsapi_init_with_args

    Could anybody please help me in this regard.

     
  • Gill
    Gill
    2012-03-19

    below is the code

    public string PdfToTiffFiles(string sourceDirectory, string sourceFile, string destinationPath)
            {
                try
                {
                    int resolution = 1600;
                    ArrayList args = new ArrayList();
                    string outputFile = sourceFile.Replace(".pdf","");
                    args.Add("gs");
                    args.Add("-dNOPAUSE");
                    args.Add("-dBATCH");
                    args.Add("-dSAFER");
                    args.Add("-dQUIET");
                    args.Add("-sDEVICE=tiffg4");
                    args.Add(String.Format("-r{0}", resolution));
                    args.Add(String.Format("-sOutputFile={0}-%d.tiff", destinationPath + "\\" + outputFile));
                    args.Add(String.Format("-f{0}", sourceDirectory + "\\" + sourceFile));

                    int result = Api.gsapi_init_with_args(GS.instance, args.Count, (string)args.ToArray(typeof(string)));
                    Api.gsapi_exit(GS.instance);
                    if (result < 0)
                        throw new InvalidOperationException(String.Format("Ghostscript failed with error code {0}.", result));
                    PdfDocument pd = new PdfDocument();  //new PdfDocument(sourceDirectory + "\\" + sourceFile);
                    pd = PdfReader.Open (sourceDirectory + "\\" + sourceFile, PdfDocumentOpenMode.Import);
                    int pageCount = pd.PageCount;
                    string files = new String;

                    for (int idx = 0; idx < pageCount; idx++)
                    {
                        files = String.Format("{0}-{1}.tiff", outputFile, idx + 1);
                    }
                    return files;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                }
            }

     
  • Russell Lang
    Russell Lang
    2012-03-20

    Some suggestions to help find the problem.

    Make sure all the command line options are correct, by using the ghostscript command line only.

    Compile ghostscript with debugging DEBUG=1 TDEBUG=1
    Then run ghostscript and step through to where ghostscript calls gsapi_init_with_args
    Look at argc and argv, then compare the values and variable types with yours.
    I suspect that you are passing it UCS2 instead of ASCII or some similar mistake.