How to convert PDF to images using C# and ImageMagick?

前端 未结 2 1276
梦毁少年i
梦毁少年i 2021-02-10 08:30

I would like to convert a PDF file to .GIF using C# and magicknet.dll. I have added the reference to the MagickNet Dll to my project.

MagickNet.Magick.Init();
Ma         


        
2条回答
  •  礼貌的吻别
    2021-02-10 09:18

    Magic.Net is a C# port for popular library ImageMagick. Install Magick.net using Nuget package from url https://www.nuget.org/packages/Magick.NET-Q16-AnyCPU/ . This way you can use C#. See code below

    Note it will append images vertically. Similarly you can append horizontally i.e. substitute images.AppendHorizontally

    using ImageMagick;
    
    string inputPdf= @"C:\my docs\input.pdf";
    string outputPng= @"C:\my docs\output.png";
    
    using (MagickImageCollection images = new MagickImageCollection())
    {
        images.Read(inputPdf);
        using (IMagickImage vertical = images.AppendVertically())
            {
                vertical.Format = MagickFormat.Png;
                vertical.Density = new Density(300);  
                vertical.Write(outputPng);
            }
    }
    

提交回复
热议问题