PDF to bmp Images (12 pages = 12 images)

十年热恋 提交于 2019-12-03 16:35:55

LibPdf

This 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.BMP); // image type
        using (var outFile = File.Create(@"..\path\to\pdf\file.bmp")) // out file
        {
            outFile.Write(pngBytes, 0, pngBytes.Length);
        }
    }
}

Or Bytescout PDF Renderer SDK

using System;

using Bytescout.PDFRenderer;


namespace PDF2BMP
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create an instance of Bytescout.PDFRenderer.RasterRenderer object and register it.
            RasterRenderer renderer = new RasterRenderer();
            renderer.RegistrationName = "demo";
            renderer.RegistrationKey = "demo";

            // Load PDF document.
            renderer.LoadDocumentFromFile("multipage.pdf");

            for (int i = 0; i < renderer.GetPageCount(); i++)
            {
                // Render first page of the document to BMP image file.
                renderer.RenderPageToFile(i, RasterOutputFormat.BMP, "image" + i + ".bmp");
            }

            // Open the first output file in default image viewer.
            System.Diagnostics.Process.Start("image0.bmp");
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!