在 C# 中读取 PDF 文件
using IronPdf;
using IronSoftware.Drawing;
using System.Collections.Generic;

// Extracting Image and Text content from Pdf Documents

// open a 128 bit encrypted PDF
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Get all text to put in a search index
string text = pdf.ExtractAllText();

// Get all Images
var allImages = pdf.ExtractAllImages();

// Or even find the precise text and images for each page in the document
for (var index = 0 ; index < pdf.PageCount ; index++)
{
    int pageNumber = index + 1;
    text = pdf.ExtractTextFromPage(index);
    List<AnyBitmap> images = pdf.ExtractBitmapsFromPage(index);
    //...
}
NuGet Download
PM > Install-Package IronPdf
在 C# 中读取 PDF 文件

在 C# 中读取 PDF 文件

IronPDF C# PDF库中的PdfDocument.ExtractAllText方法非常适合处理简单的PDF文本读取任务。 此方法可以处理源 PDF 文档中的空白和编码不一致问题。

PdfDocument.ExtractTextFromPage从PDF的特定页面读取文本。 在下面的示例中,我们看到它被迭代使用以从特定页面范围中获取文本内容。

IronPDF 也可以从 PDF 中提取原始图像。 为此,使用下面PdfDocument类中的任一方法:

  • IronSoftware.Drawing.AnyBitmap对象的形式返回。
  • byte[])。
  • ExtractImagesFromPage:提取索引页面中包含的图像。
  • ExtractImagesFromPage相同,但来源于特定页面范围或单独页面列表。
  • IronSoftware.Drawing.AnyBitmap对象。

Learn more about ExtractTextFromPage Method
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 22,024,882版本:2026.11刚刚发布