【发布时间】:2012-07-08 00:12:20
【问题描述】:
我惊喜地发现使用 iTextSharp 从 pdf 文件中提取文本是多么容易。通过关注this article,我能够使用以下简单代码将pdf文件转换为文本:
string pdfFilename = dlg.FileName;
// Show just the file name, without the path
string pdfFileNameOnly = System.IO.Path.GetFileName(pdfFilename);
lblFunnyMammalsFile.Content = pdfFileNameOnly;
string textFilename = String.Format(@"C:\Scrooge\McDuckbilledPlatypus\{0}.txt", pdfFileNameOnly);
PDFParser pdfParser = new PDFParser();
if (!pdfParser.ExtractText(pdfFilename, textFilename))
{
MessageBox.Show("there was a boo-boo");
}
问题是生成的文本文件包含这样的文本(即没有空格):
IwaspleasantlysurprisedtofindhoweasyitistouseiTextSharptoextractthetextfromatextfile.
是否有一种“外面”的算法可以接受这样的文本,并对单词中断(也称为“空格”)的位置做出最佳猜测?
【问题讨论】:
-
我会说最好解决为什么你的文本提取不包含空格的问题,然后尝试破解你为自己创建的新问题的解决方案。
-
@Gavin:由于我使用这个第三方代码来完成最困难的部分,我无法控制它为什么会这样发生,我也不会称之为我为之创建的问题我自己。
标签: c# wpf algorithm pdf text-parsing