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

一、在使用前需要在电脑上安装ghostscript,对于ghostscript的详细介绍,可自行百度查看(https://ghostscript.com/)。
以下是分享的百度云盘资源。
链接:https://pan.baidu.com/s/1uKekX4iWCEDAsZWDsDMG0Q?pwd=9kk9


提取码: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

posted @ 2024-01-02 16:03  心冰之海  阅读(149)  评论(0编辑  收藏  举报