在.NET 6里NuGet源中什么版本的Ghostscript可以将PDF转成图片
时间: 2024-03-01 11:56:17 浏览: 27
在.NET 6的NuGet源中,可以使用Ghostscript.NET.Standard 1.2.0版本来将PDF转成图片。Ghostscript.NET是一个.NET封装库,它提供了Ghostscript的API接口,可以方便地在.NET中使用Ghostscript。在使用Ghostscript.NET时,需要将Ghostscript的安装目录添加到系统环境变量中,以便Ghostscript.NET能够找到Ghostscript可执行文件。以下是使用Ghostscript.NET来将PDF转成图片的示例代码:
```csharp
using Ghostscript.NET;
using Ghostscript.NET.Rasterizer;
string inputFile = @"C:\input.pdf";
string outputFile = @"C:\output.png";
using (var rasterizer = new GhostscriptRasterizer())
{
rasterizer.Open(inputFile);
for (int pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++)
{
var img = rasterizer.GetPage(300, 300, pageNumber);
img.Save(outputFile, ImageFormat.Png);
}
}
```
在上面的示例代码中,首先创建一个GhostscriptRasterizer对象,然后打开PDF文件,遍历每一页,将每一页转成PNG格式的图片,最后保存到指定的输出文件中。请注意,此示例代码需要在已安装Ghostscript的计算机上运行。