2016-12-31 117 views
1

我正在使用C#包裝將PDF轉換爲圖像使用Ghostscript,但我似乎無法正確引用dll。 我存儲在bin文件夾中的DLL(也不知道這是保持它有或沒有最好的地方) 這裏是我的代碼:如何引用Ghostscript DLL在C#

byte[] fileData = null; 
      using (var binaryReader = new BinaryReader(Request.Files[0].InputStream)) 
      { 
       fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength); 
      } 

    string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); 

    Ghostscript.NET.Rasterizer.GhostscriptRasterizer rasterizer = null; 
    Ghostscript.NET.GhostscriptVersionInfo vesion = new Ghostscript.NET.GhostscriptVersionInfo(new Version(0, 0, 0), path + @"\gsdll64.dll", string.Empty, Ghostscript.NET.GhostscriptLicense.GPL); 
    Stream inStream = new MemoryStream(fileData); 
    MemoryStream outStream = new MemoryStream(); 
    List<Image> imageList = new List<Image>(); 
    using (rasterizer = new Ghostscript.NET.Rasterizer.GhostscriptRasterizer()) 
    { 
     rasterizer.Open(inStream, vesion, false); 
     for (int i = 1; i <= rasterizer.PageCount; i++) 
     { 
      //string pageFilePath = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(file) + "-p" + i.ToString() + ".jpg"); 
      int dpi = 200; 
      Image img = rasterizer.GetPage(dpi, dpi, i); 
      img.Save(outStream, ImageFormat.Jpeg); 
      Image img = new Image 
      { 
       imgByteArray = outStream.ToArray() 
      }; 
      imageList.Add(image); 
     } 
     rasterizer.Close(); 
    } 

我得到Ghostscript的本地所能庫未找到錯誤。 這裏的路上,我得到

enter image description here

我認爲這與雙/和做「文件://」中的DLLPath字符串。我是否也應該指定LipPath? 任何幫助?

+0

正在斌\調試UR EXE? –

+0

不只是DLL – user3159792

+0

Dll路徑看起來不正常,這就是問題所在。你從哪裏得到這個「file:」前綴?它應該看起來像「c:\ users \ raeda \ documents \ visual s ...... \ bin \ gsdll64.dll」 – HABJAN

回答

1

在你的情況,你應該做的ghostscript DLL的路徑是這樣的:

string binPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 
string gsDllPath = Path.Combine(binPath, Environment.Is64BitProcess ? "gsdll64.dll" : "gsdll32.dll");