我正在使用 ITextSharp 5.5.3.0 版,我正在尝试从 C# 中的 pdf 中提取文本。pdf是一种形式,而不是图像。这是代码:
var text = new StringBuilder();
// The PdfReader object implements IDisposable.Dispose, so you can
// wrap it in the using keyword to automatically dispose of it
using (var pdfReader = new PdfReader(inFileName))
{
// Loop through each page of the document
for (var page = 1; page <= pdfReader.NumberOfPages; page++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
var currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
currentText = Encoding.UTF8.GetString(Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
text.Append(currentText);
}
}
return text.ToString();
}
返回的文本不可用。pdf 是使用 GhostScript 生成的。
有人对问题可能有什么建议吗?或者有什么建议?