在 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剛剛發布