试图弄清楚如何使用 Ghost 脚本获取 memoryStream 并返回图像。这是执行 rasterizer.Open 后出现的代码和错误:
public static System.Drawing.Image PDFToImage(MemoryStream inputMS)
{
GhostscriptRasterizer rasterizer = null;
GhostscriptVersionInfo version = null;
if (Environment.Is64BitProcess)
version = new GhostscriptVersionInfo(
new Version(0, 0, 0), @"C:\Program Files\gs\gs9.20\bin\gswin64.exe",
string.Empty, GhostscriptLicense.GPL);
else
version = new GhostscriptVersionInfo(
new Version(0, 0, 0), @"C:\Program Files (x86)\gs\gs9.20\bin\gswin32.exe",
string.Empty, GhostscriptLicense.GPL);
int dpi = 96;
System.Drawing.Image img = null;
using (rasterizer = new GhostscriptRasterizer())
{
rasterizer.Open(inputMS, version, true);
for (int i = 1; i <= rasterizer.PageCount; i++)
{
using (MemoryStream ms = new MemoryStream())
{
img = rasterizer.GetPage(dpi, dpi, i);
img.Save(ms, ImageFormat.Jpeg);
ms.Close();
}
}
rasterizer.Close();
}
return img;
}