我正在尝试使用以下代码使用itextsharp从pdf文件中读取文本并分配给文本框(MultiLine) - (Windows桌面应用程序)
注意:此代码工作正常.
public string ReadPdfFile(string fileName)
{
StringBuilder text = new StringBuilder();
if (File.Exists(fileName))
{
PdfReader pdfReader = new PdfReader(fileName);
for (int page = 1; page <= pdfReader.NumberOfPages; page++)
{
ITextExtractionStrategy strategy = new LocationTextExtractionStrategy();
string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
text.Append(currentText);
}
pdfReader.Close();
}
return text.ToString();
}
Run Code Online (Sandbox Code Playgroud)
但我的pdf文件有一个等式
而我所得到的只是以下输出
可以在这里添加什么来实现以下文本?真的很感激任何形式的帮助!
小智 1
我使用了 itextsharp,我 100% 确定这是不可能的。问题出在pdf格式本身。它不包含引用某些文本的任何标签。PDF 包含内容的特定图形表示,该内容在 pdf 页面上有其位置。如果没有 OCR,甚至无法检测粗体文本。Pdf 不是一个很好解析的格式。
我的问题比你的更容易,阅读 pdf 简直是地狱。它只是文本,但格式为 2 页合一(2 列文本)。Itextsharp 通过坐标读取内容,因此当他读取第一列的第一行而不是第二列的第一行时,我的文本变得混乱(不是文本流)。至于latex,latex代码转换为pdf后,并没有反转为latex代码。
| 归档时间: |
|
| 查看次数: |
496 次 |
| 最近记录: |