.Net Core 使用Magick.NET 将PDF文件转成图片


一、在使用前需要在电脑上安装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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM