提取文本
The Documentize PDF Extractor for .NET 简化了从 PDF 文档中提取文本的过程。无论您需要纯文本、原始文本还是普通文本,此插件都能高效提取文本,并根据需求保留或省略格式。
如何从 PDF 文件提取文本
要从 PDF 文件提取文本,请按照以下步骤操作:
- 创建
ExtractTextOptions实例以配置输入文件路径。 - 运行
Extract方法进行文本提取。
1// Create ExtractTextOptions object to set input file path
2var options = new ExtractTextOptions("path_to_your_pdf_file.pdf");
3// Perform the process and get the extracted text
4var textExtracted = PdfExtractor.Extract(options);如何从 PDF 流提取文本
要从 PDF 流提取文本,请按照以下步骤操作:
- 创建
ExtractTextOptions实例以配置输入流。 - 运行
Extract方法进行文本提取。
1// Create ExtractTextOptions object to set input stream
2var stream = File.OpenRead("path_to_your_pdf_file.pdf");
3var options = new ExtractTextOptions(stream);
4// Perform the process and get the extracted text
5var textExtracted = PdfExtractor.Extract(options);文本提取模式
ExtractTextOptions 提供三种提取模式,满足不同需求的灵活性。
- Pure Mode:保留原始格式,包括空格和对齐。
- Raw Mode:不保留格式,适用于原始数据处理。
- Flatten Mode:使用坐标表示 PDF 内容的文本片段。
1// Create ExtractTextOptions object to set input file path and TextFormattingMode
2var options = new ExtractTextOptions("path_to_your_pdf_file.pdf", TextFormattingMode.Pure);
3// Perform the process and get the extracted text
4var textExtracted = PdfExtractor.Extract(options);最简方式从 PDF 文件提取文本
1// Perform the process and get the extracted text
2var textExtracted = PdfExtractor.Extract(new ExtractTextOptions("path_to_your_pdf_file.pdf", TextFormattingMode.Pure));关键特性:
- Pure Mode:在保留原始格式的同时提取文本。
- Raw Mode:提取不含任何格式的文本。
- Flatten Mode:提取不含特殊字符或格式的文本。