一、在使用前需要在電腦上安裝ghostscript,對於ghostscript的詳細介紹,可自行百度查看(https://ghostscript.com/)。
以下是分享的百度雲盤資源。
鏈接:https://pan.baidu.com/s/1tjfcFCr3AqRslAwiKUY0Zw
提取碼:0oms
二、在NuGet中安裝 magick.net-Q16-AnyCPU。如下圖
三、做好准備工作就可以上代碼了
try
{
string path = @"D:\out\測試文檔.pdf";
MagickReadSettings settings = new MagickReadSettings();
settings.Density = new Density(900, 900); //設置質量
using (MagickImageCollection images = new MagickImageCollection())
{
images.Read(path, settings);
for (int i = 0; i < images.Count; i++)
{
MagickImage image = (MagickImage)images[i];
image.Format = MagickFormat.Png;
image.Write(path.Replace(Path.GetExtension(path), "") + "-" + i + ".png");
}
}
}
catch (Exception ex)
{
}
四、更多Magick.NET的運用可參考
https://github.com/dlemstra/Magick.NET/blob/master/docs/Readme.md