pdf- parse- 已固定
快速修复 pdf-parse 库 - 它现在工作了!
纯javascript 跨平台模块从 PDF 中取出文本.
类似软件包
- pdf2json (英语) buggy, 不再支持, 内存漏出, 扔出无法捕捉的致命错误
- j-pdfjson (英语) pdf2json 叉数
- pdf- parser 软件 没有测试
- pdf阅读器 使用 pdf2json 软件
- pdf 摘录 不使用 xpdf 的跨平台
安装
npm install pdf-parse
基本使用法 - 本地文件
const fs = require('fs');
const pdf = require('pdf-parse');
let dataBuffer = fs.readFileSync('path to PDF file...');
pdf(dataBuffer).then(function(data) {
// number of pages
console.log(data.numpages);
// number of rendered pages
console.log(data.numrender);
// PDF info
console.log(data.info);
// PDF metadata
console.log(data.metadata);
// PDF.js version
// check https://mozilla.github.io/pdf.js/getting_started/
console.log(data.version);
// PDF text
console.log(data.text);
});
基本用途 - HTTP
你用得着 爬行请求 使用 pdf-parse
例外处理
const fs = require('fs');
const pdf = require('pdf-parse');
let dataBuffer = fs.readFileSync('path to PDF file...');
pdf(dataBuffer).then(function(data) {
// use data
})
.catch(function(error){
// handle exceptions
})
扩展
// default render callback
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) {
let lastY, text = '';
for (let item of textContent.items) {
if (lastY == item.transform[5] || !lastY){
text += item.str;
}
else{
text += '\n' + item.str;
}
lastY = item.transform[5];
}
return text;
});
}
let options = {
pagerender: render_page
}
let dataBuffer = fs.readFileSync('path to PDF file...');
pdf(dataBuffer,options).then(function(data) {
//use new format
});
选项
const DEFAULT_OPTIONS = {
// internal page parser callback
// you can set this option, if you need another format except raw text
pagerender: render_page,
// max page number to parse
max: 0,
//check https://mozilla.github.io/pdf.js/getting_started/
version: 'v1.10.100'
}
页面 (回电)
如果需要除原始文本外的其他格式.
最大数 (数目)
要解析的最大页码 。 如果数值小于或等于 0,则解析器会使全部页面.
版本 (字符串,pdf.js版本)
检查 页:1
'default''v1.9.426''v1.10.100''v1.10.88''v2.0.550'
默认 版本为 v1.10.100 (英语)
mozilla.github.io/pdf.js (英语)
测试
支助
我积极地使用这个包裹,所以它是我的最高优先。 你可以在WhatsApp上谈论任何信息,想法和建议.
提交问题
如果发现错误或错误,您可以通过提交问题来帮助 GitLab 仓库
创建合并请求
GitLab称它为合并请求,而不是拉取请求.
许可证
麻省理工学院执照 而所有的依赖都是麻省理工学院或BSD许可.