@cyber2024/pdf-parse-fixed

中文文档
1.2.5发布于 2023/02/17MITTypeScriptCommonJS近 30 天下载 2343

纯javascript 跨平台模块取自PDFs的文本.

中文使用文档
文档目录15 节
  1. 类似软件包
  2. 安装
  3. 基本使用法 - 本地文件
  4. 基本用途 - HTTP
  5. 例外处理
  6. 扩展
  7. 选项
  8. 页面 (回电)
  9. 最大数 (数目)
  10. 版本 (字符串,pdf.js版本)
  11. 测试
  12. 支助
  13. 提交问题
  14. 创建合并请求
  15. 许可证

pdf- parse- 已固定

快速修复 pdf-parse 库 - 它现在工作了!

纯javascript 跨平台模块从 PDF 中取出文本.

version downloads node status

类似软件包

安装

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
})

扩展

  • v1.0.9 及以上分页调回 更改日志
  • 如果您需要Json这样的其他格式, 您可以用回调更改页面渲染行为
  • 检查出来 页:1
// 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上谈论任何信息,想法和建议.

WhatsApp

提交问题

如果发现错误或错误,您可以通过提交问题来帮助 GitLab 仓库

创建合并请求

GitLab称它为合并请求,而不是拉取请求.

许可证

麻省理工学院执照 而所有的依赖都是麻省理工学院或BSD许可.

版本与发布记录

@cyber2024/pdf-parse-fixed 共发布 6 个版本,首次发布于 2023/02/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.5latest2023/02/173 年前
1.2.42023/02/173 年前
1.2.32023/02/163 年前
1.2.22023/02/163 年前
1.2.12023/02/153 年前
1.1.12023/02/153 年前

关于 @cyber2024/pdf-parse-fixed 的常见问题

@cyber2024/pdf-parse-fixed 是什么?

纯javascript 跨平台模块取自PDFs的文本.

如何安装 @cyber2024/pdf-parse-fixed?

在项目目录运行 npm install @cyber2024/pdf-parse-fixed,或使用 pnpm add / yarn add / bun add。

@cyber2024/pdf-parse-fixed 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cyber2024/pdf-parse-fixed 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cyber2024/pdf-parse-fixed 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=6.8.1。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cyber2024/pdf-parse-fixed 可以商用吗?

@cyber2024/pdf-parse-fixed 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cyber2024/pdf-parse-fixed 的下载量有多少?

根据 npm 官方下载统计,@cyber2024/pdf-parse-fixed 在 2026/10/11 – 2026/11/09 这 30 天内被下载 2,343 次,日均约 78 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cyber2024/pdf-parse-fixed 还在维护吗?

最新版本 1.2.5 发布于 2023/02/17(3 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/02/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。