这个问题已经在这里讨论过:GhostscriptRasterizer Objects Returns 0 as PageCount value 但是这个问题的答案并没有帮助我解决问题。
就我而言,从 kat 到旧版本的 Ghostscript 没有帮助。26 和 25。我的 PageCount = 0,如果版本低于 27,我收到错误“未找到本机 Ghostscript 库”。
private static void PdfToPng(string inputFile, string outputFileName)
{
var xDpi = 100; //set the x DPI
var yDpi = 100; //set the y DPI
var pageNumber = 1; // the pages in a PDF document
using (var rasterizer = new GhostscriptRasterizer()) //create an instance for GhostscriptRasterizer
{
rasterizer.Open(inputFile); //opens the PDF file for rasterizing
//set the output image(png's) complete path
var outputPNGPath = Path.Combine(outputFolder, string.Format("{0}_Page{1}.png", outputFileName,pageNumber));
//converts the PDF pages to png's
var pdf2PNG = rasterizer.GetPage(xDpi, yDpi, pageNumber);
//save the png's
pdf2PNG.Save(outputPNGPath, ImageFormat.Png);
Console.WriteLine("Saved " + outputPNGPath);
}
}