2014-10-07 139 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