我必须逐页将 pdf 解构/提取为位图图像。这将通过我设置的网络服务在服务器上完成。我该如何做对?它必须一页一页(每张图片一页)。 我真的被困住了,我知道你们中的一位天才有我一直在寻找的答案。
我试过:http://www.pdfsharp.net/wiki/ExportImages-sample.ashx哪个不能正常工作。
我正在使用 C#; PDF 没有密码保护; 如果此解决方案可以将 Uri 作为 PDF 位置的参数,那就太好了!
解决方案根本不应该依赖于 Acrobat PDF Reader
很长一段时间以来,我一直在努力尝试使用 MigraDoc 和 PDFSharp 及其替代方案来解决上述问题。
任何帮助/建议/代码将不胜感激!!
提前致谢!
最佳答案
此库将 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);
}
}
}
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/