我正在尝试解析一个超过300页的pdf。我正在使用pdf-parse npm 包。pdf有300页。但我的应用程序在解析 pdf 时崩溃了。我的问题是有什么方法可以一次解析一页?下面是我尝试过的代码。
function render_page(pageData) {
//check documents https://mozilla.github.io/pdf.js/
let render_options = {
//replaces all occurrences of whitespace with standard spaces (0x20). The default value is `false`.
normalizeWhitespace: false,
//do not attempt to combine same line TextItem's. The default value is `false`.
disableCombineTextItems: false
}
return pageData.getTextContent(render_options)
.then(function (textContent) {
return textContent.items.map(function (s) {
return s.str
}).join(''); // value page text
})
}
//textContent.items.map
//.map(function (s) { return s.str; }).join('{newline}'); // value page text
let dataBuffer …Run Code Online (Sandbox Code Playgroud) 我有一个asp.net Core 2.0 C#读取/解析PDF文件并获取文本的应用程序。在此,我想读取具有特定标签名称的特定值。你可以看到下面的图片我想要得到的价值171857是Invoice数量并将其存储在数据库中。

我已经尝试过使用以下代码读取pdf iTextSharp。
using (PdfReader reader = new PdfReader(fileName))
{
StringBuilder sb = new StringBuilder();
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
for (int page = 0; page < reader.NumberOfPages; page++)
{
string text = PdfTextExtractor.GetTextFromPage(reader, page + 1, strategy);
if (!string.IsNullOrWhiteSpace(text))
{
sb.Append(Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(text))));
}
}
var pdfText = sb.ToString();
}
Run Code Online (Sandbox Code Playgroud)
在pdfText变量中,我将从pdf中获取所有文本内容,但这似乎不是获取发票编号的正确方法。还有其他方法可以通过其标签名称从pdf读取pdf的特定内容,例如我们将提供标签名称Invoice,并且它将返回值171857,例如与其他第三方pdf阅读器库一样?
任何帮助或建议,将不胜感激。
谢谢