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

前端 未结 2 1272
梦毁少年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:11

    ImageMagick requires GhostScript to Interpret PDF files. If you want you can call the GhostScript dll directly (contact me via my profile, I will send you a c# wrapper)

    Alternatively you can use the GhostScript command line or a commercial 3rd party component, eg the PDF libraries from Tall Components.

    0 讨论(0)
  • 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);
            }
    }
    
    0 讨论(0)
提交回复
热议问题