C# 读取 PDF 指南
This article was translated from English: Does it need improvement?
TranslatedView the article in English
今天,我们将介绍一种简单的方法来读取PDF内容并提取其原始格式的文本。 这可以针对整个文档或特定页面完成,所有这些都在您的C#项目中进行。



开始使用IronPDF
立即在您的项目中开始使用IronPDF,并享受免费试用。
如何在C#中读取PDF文件
- 下载用于 PDF 读写的 IronPDF C# 库
- 安装使用 通过 NuGet 获取 IronPDF 测试图书馆
- 读取 PDF 文件,提取内容,甚至提取高质量的原始图像
- 使用 C# 表单向您展示阅读 PDF 内容的完美输出效果
- 查看 PDF 输出
在C#中读取PDF文件
使用这个C#库,我们可以读取PDF文件,提取内容,甚至提取高质量和原始图像。 请参见下面的示例,了解我们在 .NET 环境中使用不同功能来满足PDF阅读需求的多种方式。
:path=/static-assets/pdf/content-code-examples/how-to/csharp-read-pdf-read-pdf.cs
using IronPdf;
using IronSoftware.Drawing;
using System.Collections.Generic;
// Select the desired PDF File
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Extract all text from an pdf
string allText = pdf.ExtractAllText();
// Get all Images
IEnumerable<AnyBitmap> AllImages = pdf.ExtractAllImages();
// Else combine above both functionality using PageCount
for (var index = 0; index < pdf.PageCount; index++)
{
string Text = pdf.ExtractTextFromPage(index);
IEnumerable<AnyBitmap> Images = pdf.ExtractImagesFromPage(index);
}
Imports IronPdf
Imports IronSoftware.Drawing
Imports System.Collections.Generic
' Select the desired PDF File
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Extract all text from an pdf
Private allText As String = pdf.ExtractAllText()
' Get all Images
Private AllImages As IEnumerable(Of AnyBitmap) = pdf.ExtractAllImages()
' Else combine above both functionality using PageCount
For index = 0 To pdf.PageCount - 1
Dim Text As String = pdf.ExtractTextFromPage(index)
Dim Images As IEnumerable(Of AnyBitmap) = pdf.ExtractImagesFromPage(index)
Next index
VB C#
输出
我们使用了一个C#表单来展示读取PDF内容的完美输出。 通过这种方法,一切都以简单为本,尽可能使用最少的代码来满足您的项目需求。