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的本地所能庫未找到錯誤。 這裏的路上,我得到
我認爲這與雙/和做「文件://」中的DLLPath字符串。我是否也應該指定LipPath? 任何幫助?
正在斌\調試UR EXE? –
不只是DLL – user3159792
Dll路徑看起來不正常,這就是問題所在。你從哪裏得到這個「file:」前綴?它應該看起來像「c:\ users \ raeda \ documents \ visual s ...... \ bin \ gsdll64.dll」 – HABJAN