C# 读取 PDF 指南

This article was translated from English: Does it need improvement?
Translated
View the article in English

今天,我们将介绍一种简单的方法来读取PDF内容并提取其原始格式的文本。 这可以针对整个文档或特定页面完成,所有这些都在您的C#项目中进行。

Csharp Parse Pdf1 related to C# 读取 PDF 指南
Csharp Parse Pdf2 related to C# 读取 PDF 指南
Csharp Parse Pdf3 related to C# 读取 PDF 指南

开始使用IronPDF

立即在您的项目中开始使用IronPDF,并享受免费试用。

第一步:
green arrow pointer


在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内容的完美输出。 通过这种方法,一切都以简单为本,尽可能使用最少的代码来满足您的项目需求。

~ PDF

Csharp Read Pdf4 related to ~ PDF

~ C# 表格

Csharp Read Pdf5 related to ~ C# 表格

图书馆快速访问

Documentation related to 图书馆快速访问

图书馆文件

IronPDF 库的文档可在方便的 API Reference 中查阅和共享。

IronPDF API 参考文档