2014-10-07 22 views
0

当我将pdf转换为image时,我遇到了一个奇怪的问题。我正在执行pdf上的转换代码。它第一次运行良好,然后开始给出我从下一次出现“ghostscript转换错误”。给出错误的代码如下所示。Ghostscript在第一次正确执行后给出“Ghostscript转换错误”

int result = InitAPI(gsInstancePtr, args.Length, args); 

它返回一个-100的错误代码。完整的代码如下。

public static void CallAPI(string[] args) 
    { 
     // Get a pointer to an instance of the Ghostscript API and run the API with the current arguments 
     IntPtr gsInstancePtr; 
     lock (resourceLock) 
     { 
      CreateAPIInstance(out gsInstancePtr, IntPtr.Zero); 
      try 
      { 
       int result = InitAPI(gsInstancePtr, args.Length, args); 

       if (result < 0) 
       { 
        throw new ExternalException("Ghostscript conversion error", result); 
       } 
      } 
      finally 
      { 
       Cleanup(gsInstancePtr); 
      } 
     } 
    } 

    /// <summary> 
    /// Frees up the memory used for the API arguments and clears the Ghostscript API instance 
    /// </summary> 
    private static void Cleanup(IntPtr gsInstancePtr) 
    { 
     ExitAPI(gsInstancePtr); 
     DeleteAPIInstance(gsInstancePtr); 
    } 

我在做什么错?

+0

您是否尝试将第一个'arg'留空(空白)?当通过API调用Ghostscript时,忽略第一个参数(arg [0])。 – HABJAN 2014-10-07 08:10:16

回答

0

那么,第一个薄,你没有使用Ghostscript,至少不是直接。可能你正在使用Ghostscript.NET?

从Ghostscript本身的错误-100意味着一个致命的错误,额外的信息可能在stdout或stderr上可用,您需要捕获并报告该错误。

+0

他没有使用Ghostscript.NET。他通过P/Invoke直接调用API。 – HABJAN 2014-10-07 08:04:13

+0

好的,你是怎么知道的? – KenS 2014-10-07 08:11:39

+0

在Ghostscript.NET中找不到这些函数名称,而且,Ghostscript.NET需要关心创建,调用,退出和删除Ghostscript实例。 – HABJAN 2014-10-07 08:18:46