我有这段代码可以将 pdf 转换为 tif,它比 ImageMagick 库更快,所以我必须使用它。每件事都很好,但是当我设置x 和 y dpi时,它总是被忽略。我尝试了不同版本的 NuGet GhostScript,我也尝试了不同版本的 ghostscript.exe 仍然是同样的问题
这是我的代码:
var xDpi = 300; //set the x DPI
var yDpi = 300; //set the y DPI
using (var rasterizer = new GhostscriptRasterizer()) //create an instance for GhostscriptRasterizer
{
rasterizer.Open(fileName); //opens the PDF file for rasterizing
int PdfPages = rasterizer.PageCount;
for (int pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++)
{
//set the output image(png's) complete path
string outputPNGPath = Path.Combine(fileNameResultDirectory, "00" + pageNumber.ToString() + ".tif");
//converts the PDF pages to png's
Image pdf2PNG = rasterizer.GetPage(xDpi, yDpi, pageNumber);//it gets ignored here.
//save the png's
pdf2PNG.Save(outputPNGPath, ImageFormat.Tiff);
}
}
也试过:
rasterizer.CustomSwitches.Add("-r300x300");
也试过:
private static void Test()
{
var localGhostscriptDll = Path.Combine(Environment.CurrentDirectory, "gsdll64.dll");
var localDllInfo = new GhostscriptVersionInfo(localGhostscriptDll);
int desired_x_dpi = 160;
int desired_y_dpi = 160;
string inputPdfPath = @"d:\d.pdf";
string outputPath = @"d:\Test\test.jpg";
GhostscriptRasterizer _rasterizer = new GhostscriptRasterizer();
_rasterizer.Open(inputPdfPath, localDllInfo, false);
for (int pageNumber = 1; pageNumber <= _rasterizer.PageCount; pageNumber++)
{
string pageFilePath = Path.Combine(outputPath, "Page-" + pageNumber.ToString() + ".png");
Image img = _rasterizer.GetPage(desired_x_dpi, desired_y_dpi, pageNumber);
img.Save(pageFilePath, ImageFormat.Png);
}
_rasterizer.Close();
}
在这种情况下,我手动将 gsdll32.dll 添加到此环境路径 ..\bin\debug 但我收到此错误: Ghostscript.NET.GhostscriptException:'无法为符号'gsapi_revision'创建导出函数的委托''
知道为什么忽略 x 和 y dpi 以及在属性中将其设置为 96 或 120 作为垂直/水平分辨率。我很感激任何帮助。