PDF转换为bmp图像(12页= 12张图像) [英] PDF to bmp Images (12 pages = 12 images)

查看:113
本文介绍了PDF转换为bmp图像(12页= 12张图像)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须逐页将pdf解构/提取为位图图像.这将通过我已设置的Web服务在服务器上完成.我该如何正确处理?它必须是一页一页(每张图像一页). 我真的很困惑,我知道你们当中的一个天才都有我一直在寻找的答案.

I have to deconstruct/extract a pdf page by page into bitmap images. This will be done on a server via a web service which I've setup. How do I get this right? It has to be page by page (1 page per image). I am really stuck and I know one of you geniuses have the answer that I've been looking for.

我尝试过: http://www.pdfsharp.net/wiki/ExportImages- sample.ashx 不能正常工作.

I have tried: http://www.pdfsharp.net/wiki/ExportImages-sample.ashx Which didn't work correctly.

我正在使用C#; PDF不受密码保护; 如果此解决方案可以将Uri作为PDF位置的参数,那就太好了!

I am using C#; The PDF is not password protected; If this solution could take a Uri as a parameter for the location of the PDF it would be excellent!

该解决方案完全不应该依赖Acrobat PDF Reader

很长一段时间以来,我一直在努力使用MigraDoc和PDFSharp及其替代方案来解决上述问题.

I have been struggling for a very long time trying to use MigraDoc and PDFSharp and their alternatives to achieve the aforementioned problem.

任何帮助/建议/代码将不胜感激!

ANY help/advice/code would be greatly appreciated!!

提前谢谢!

推荐答案

LibPdf

此库将PDF文件转换为图像.支持的图像格式为PNG和BMP,但您可以轻松添加更多图像.

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

用法示例:

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);
        }
    }
}

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");
        }
    }
}

这篇关于PDF转换为bmp图像(12页= 12张图像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆