@cyber2024/pdf-parse-fixed

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

Pure javascript cross-platform module to extract text from PDFs.

原始使用文档
文档目录15 节
  1. Similar Packages
  2. Installation
  3. Basic Usage - Local Files
  4. Basic Usage - HTTP
  5. Exception Handling
  6. Extend
  7. Options
  8. pagerender (callback)
  9. max (number)
  10. version (string, pdf.js version)
  11. Test
  12. Support
  13. Submitting an Issue
  14. Creating a Merge Request
  15. License

pdf-parse-fixed

A quick fix for the pdf-parse library - it works now!

Pure javascript cross-platform module to extract texts from PDFs.

version downloads node status

Similar Packages

Installation

npm install pdf-parse

Basic Usage - Local Files

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

Basic Usage - HTTP

You can use crawler-request which uses the pdf-parse

Exception Handling

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

Extend

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

Options

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

pagerender (callback)

If you need another format except raw text.

max (number)

Max number of page to parse. If the value is less than or equal to 0, parser renders all pages.

version (string, pdf.js version)

check pdf.js

  • 'default'
  • 'v1.9.426'
  • 'v1.10.100'
  • 'v1.10.88'
  • 'v2.0.550'

default version is v1.10.100
mozilla.github.io/pdf.js

Test

Support

I use this package actively myself, so it has my top priority. You can chat on WhatsApp about any infos, ideas and suggestions.

WhatsApp

Submitting an Issue

If you find a bug or a mistake, you can help by submitting an issue to GitLab Repository

Creating a Merge Request

GitLab calls it merge request instead of pull request.

License

MIT licensed and all it's dependencies are MIT or BSD licensed.

版本与发布记录

@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 是什么?

Pure javascript cross-platform module to extract text from 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 和提交记录判断。