【发布时间】:2019-01-16 10:07:27
【问题描述】:
我正在尝试使用 pdf 框从文件中读取文本,以便在文件系统中对其进行排序。我正在使用 C#。我可以从互联网上阅读示例 pdf,但由于某种原因,我尝试从中读取的 pdf 仅返回一个没有实际字符的字符串。这是我正在使用的代码:
using org.apache.pdfbox.pdmodel;
using org.apache.pdfbox.util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PDFBoxTest
{
class Program
{
static void Main(string[] args)
{
string fileName = @"C:\Users\Development\Desktop\purchaseOrder.pdf";
PDDocument doc = null;
try
{
doc = PDDocument.load(fileName);
PDFTextStripper stripper = new PDFTextStripper();
Console.WriteLine(stripper.getText(doc));
}
finally
{
if (doc != null)
{
doc.close();
}
}
Console.ReadLine();
}
}
}
这是对我不起作用的 pdf 链接。一个已保存,另一个是使用“字母”设置打印的。
提前致谢! https://drive.google.com/drive/folders/1iSadM0ikdrhHsvemNVdyEl3BeTIhm39U?usp=sharing
【问题讨论】:
-
请阅读文本提取FAQ:pdfbox.apache.org/2.0/faq.html#text-extraction。您是否能够从 Adobe Reader 获得任何文本?
标签: c# .net parsing pdf pdfbox