.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