# @cyber2024/pdf-parse-fixed 中文文档

规范地址：https://npmcn.com/package/%40cyber2024/pdf-parse-fixed/

版本：1\.2\.5
npm 元数据更新时间：2023-02-17T05:53:30.488Z
中文译文更新时间：2026-11-11T09:47:09.807Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40cyber2024/pdf-parse-fixed
原文对照：https://npmcn.com/package/%40cyber2024/pdf-parse-fixed/?lang=original
项目主页：https://gitlab.com/autokent/pdf-parse
源码仓库：https://gitlab.com/autokent/pdf-parse

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：29.3 MB，58 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=6\.8\.1
- 运行依赖：3 个
- 首次发布：2023-02-14T16:23:21.243Z
- 最新版本发布：2023-02-17T05:53:30.245Z
- 近 30 天下载量：2343（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：6（近 12 个月 0 个）

## 中文简介

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

## 安装

```sh
npm install @cyber2024/pdf-parse-fixed
```

也可以使用：`pnpm add @cyber2024/pdf-parse-fixed`、`yarn add @cyber2024/pdf-parse-fixed`、`bun add @cyber2024/pdf-parse-fixed`

## README

# pdf- parse- 已固定

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

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

[![version](https://img.shields.io/npm/v/pdf-parse.svg)](https://www.npmjs.org/package/pdf-parse) [![downloads](https://img.shields.io/npm/dt/pdf-parse.svg)](https://www.npmjs.org/package/pdf-parse) [![node](https://img.shields.io/node/v/pdf-parse.svg)](https://nodejs.org/) [![status](https://gitlab.com/autokent/pdf-parse/badges/master/pipeline.svg)](https://gitlab.com/autokent/pdf-parse/pipelines)

## 类似软件包

-   [pdf2json (英语)](https://www.npmjs.com/package/pdf2json) buggy, 不再支持, 内存漏出, 扔出无法捕捉的致命错误
-   [j-pdfjson (英语)](https://www.npmjs.com/package/j-pdfjson) pdf2json 叉数
-   [pdf- parser 软件](https://github.com/dunso/pdf-parse) 没有测试
-   [pdf阅读器](https://www.npmjs.com/package/pdfreader) 使用 pdf2json 软件
-   [pdf 摘录](https://www.npmjs.com/package/pdf-extract) 不使用 xpdf 的跨平台

## 安装

`npm install pdf-parse`

## 基本使用法 - 本地文件

```js
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

你用得着 [爬行请求](https://www.npmjs.com/package/crawler-request) 使用 `pdf-parse`

## 例外处理

```js
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 及以上分页调回 [更改日志](https://gitlab.com/autokent/pdf-parse/blob/master/CHANGELOG)
-   如果您需要Json这样的其他格式, 您可以用回调更改页面渲染行为
-   检查出来 [页:1](https://mozilla.github.io/pdf.js/)

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

## 选项

```js
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](https://mozilla.github.io/pdf.js/getting_started/)

-   `'default'`
-   `'v1.9.426'`
-   `'v1.10.100'`
-   `'v1.10.88'`
-   `'v2.0.550'`

> _默认_ 版本为 _v1.10.100 (英语)_  
> [mozilla.github.io/pdf.js (英语)](https://mozilla.github.io/pdf.js/getting_started/#download)

## 测试

-   `mocha` 或者说 `npm test`
-   检查 [测试文件夹](https://gitlab.com/autokent/pdf-parse/tree/master/test) 财务报告和审定财务报表 [快速启动.js](https://gitlab.com/autokent/pdf-parse/blob/master/quickstart.js) 额外用途.

## 支助

我积极地使用这个包裹,所以它是我的最高优先。 你可以在WhatsApp上谈论任何信息,想法和建议.

[![WhatsApp](https://img.shields.io/badge/style-chat-green.svg?style=flat&label=whatsapp)](https://api.whatsapp.com/send?phone=905063042480&text=Hi%2C%0ALet%27s%20talk%20about%20pdf-parse)

### 提交问题

如果发现错误或错误,您可以通过提交问题来帮助 [GitLab 仓库](https://gitlab.com/autokent/pdf-parse/issues)

### 创建合并请求

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

-   [第一次时间指南](https://about.gitlab.com/2016/06/16/fearless-contribution-a-guide-for-first-timers/)
-   [如何创建合并请求](https://docs.gitlab.com/ee/gitlab-basics/add-merge-request.html)
-   检查 [贡献指南](https://gitlab.com/autokent/pdf-parse/blob/master/CONTRIBUTING.md)

## 许可证

[麻省理工学院执照](https://gitlab.com/autokent/pdf-parse/blob/master/LICENSE) 而所有的依赖都是麻省理工学院或BSD许可.

## 常见问题

### @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 和提交记录判断。

