【发布时间】:2016-12-31 12:42:59
【问题描述】:
我正在使用 C# 包装器使用 Ghostscript 将 PDF 转换为图像,但是我似乎无法正确引用 dll。 我将 DLL 存储在 bin 文件夹中(也不知道这是否是保存它的最佳位置) 这是我的代码:
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 字符串中的双 / 和 'file://' 有关。我还应该指定 LipPath 吗? 有什么帮助吗??
【问题讨论】:
-
你的 exe 在 bin\debug 下吗?
-
不只是 DLL
-
Dll 路径看起来不对,这就是问题所在。你从哪里得到这个“文件:”前缀?它应该看起来像“c:\users\raeda\documents\visual s......\bin\gsdll64.dll”
标签: c# pdf ghostscript