c# - PDF 到 bmp 图片(12 页 = 12 张图片)

标签 c# asp.net pdf bitmap converter

我必须逐页将 pdf 解构/提取为位图图像。这将通过我设置的网络服务在服务器上完成。我该如何做对?它必须一页一页(每张图片一页)。 我真的被困住了,我知道你们中的一位天才有我一直在寻找的答案。

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

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

解决方案根本不应该依赖于 Acrobat PDF Reader

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

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

提前致谢!

最佳答案

LibPdf

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

使用示例:

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

关于c# - PDF 到 bmp 图片(12 页 = 12 张图片),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24653716/

相关文章:

excel - 从第三方黑莓应用程序启动 Documents To Go 应用程序

python - WeasyPrint:修复了每个 pdf 页面上长表重叠的页脚标签

c# - Windows Azure 结束连接并返回 324 错误代码

c#静态构造函数问题

c# - 服务帐户无法从 Windows 证书存储加载 X509Certificate

asp.net - 如何在另一个下拉列表事件期间刷新下拉列表而不刷新整个网页?

python - 在 Django 中从 http 请求生成 PDF

c# - 创建线程 - Task.Factory.StartNew 与 new Thread()

c# - 如何从静态方法访问控件?

asp.net - ASP .NET 4.0 如何在 EnableCDN=true 时重定向/覆盖 ScriptManager 的默认 CDN 路径