Convert PDF to Image without using Ghostscript DLL

前端 未结 4 1955
执念已碎
执念已碎 2020-11-29 03:56

Is there any way, I can convert HTML Document (file not URL) to Image, or PDF to image?

I am able to do the above using Ghostscript DLL , Is there any other way , I

4条回答
  •  清歌不尽
    2020-11-29 04:37

    Use LibPdf, for PDF to Image conversion

    LibPdf library converts converts PDF file to an image. Supported image formats are PNG and BMP, but you can easily add more.

    Usage example:

    using (FileStream file = File.OpenRead(@"..\path\to\pdf\file.pdf")) // in file
    {
        var bytes = new byte[file.Length];
        file.Read(bytes, 0, bytes.Length);
        using (var pdf = new LibPdf(bytes))
        {
            byte[] pngBytes = pdf.GetImage(0,ImageType.PNG); // image type
            using (var outFile = File.Create(@"..\path\to\pdf\file.png")) // out file
            {
                outFile.Write(pngBytes, 0, pngBytes.Length);
            }
        }
    }
    

    ImageMagick, you should also look at this freely available and powerful tool. It's capable of doing what you want and also provides some .NET bindings (as well as bindings to several other languages).

    In its simplest form, it's just like writing a command

    convert file.pdf imagefile.png
    

提交回复
热议问题