getRawTextContent() returns the lines of every page in reverse order (bottom to top) since 4.0.3
还没有人认领这个 Issue。
评估
- 难度
- 1/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 90/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, node.js
调研方向
阅读 lib/pdftextsorter.js,检查 issue 中描述的行排序。查看 bidiTexts 的 y 坐标与页面视觉顺序之间的关系,然后运行提供的三行复现示例,并确认 getRawTextContent() 按 First, Second, Third line 的顺序输出,后接分页符。
由索引模型根据 Issue 内容生成。
描述
Since 4.0.3, getRawTextContent() (and the CLI's -c content output) emits each page's lines from the bottom of the page to the top. A plain three-line page comes out last line first.
Reproduction (npm i [email protected], run with node repro.mjs):
import fs from "node:fs";
import PDFParser from "pdf2json";
// one page, three lines drawn top to bottom (y = 700, 680, 660)
const content = "BT /F1 12 Tf 72 700 Td (First line) Tj 0 -20 Td (Second line) Tj 0 -20 Td (Third line) Tj ET";
const objs = [
"<< /Type /Catalog /Pages 2 0 R >>",
"<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << /Font << /F1 4 0 R >> >> /Contents 5 0 R >>",
"<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>",
`<< /Length ${content.length} >>\nstream\n${content}\nendstream`,
];
let pdf = "%PDF-1.4\n";
const offsets = objs.map((o, i) => { const off = pdf.length; pdf += `${i + 1} 0 obj\n${o}\nendobj\n`; return off; });
const xref = pdf.length;
pdf += `xref\n0 ${objs.length + 1}\n0000000000 65535 f \n` + offsets.map(o => `${String(o).padStart(10, "0")} 00000 n \n`).join("");
pdf += `trailer\n<< /Size ${objs.length + 1} /Root 1 0 R >>\nstartxref\n${xref}\n%%EOF\n`;
const parser = new PDFParser(null, true);
parser.on("pdfParser_dataError", (e) => console.error(e.parserError));
parser.on("pdfParser_dataReady", () => console.log(JSON.stringify(parser.getRawTextContent())));
fs.writeFileSync("lines.pdf", pdf, "latin1");
parser.loadPDF("lines.pdf");
Actual (pdf2json 4.0.3, 4.1.0, 4.1.1 / master 5edaa03 on Node v26.13.0):
"Third line\r\nSecond line\r\nFirst line\r\n----------------Page (0) Break----------------\r\n"
Expected (what 4.0.2 and pdftotext lines.pdf - produce):
"First line\r\nSecond line\r\nThird line\r\n----------------Page (0) Break----------------\r\n"
The same happens with ordinary PDFs, such as the Google Docs sample.pdf attached to #421 (comment of 2026-04-28).
The spatial sort added in #422 (lib/pdftextsorter.js, lines.sort((a, b) => a[0].y - b[0].y)) sorts lines by ascending y, but bidiTexts y coordinates are in PDF user space where y grows upward, so ascending y orders lines from bottom to top instead of top to bottom (lines.sort((a, b) => b[0].y - a[0].y)).
Credit: https://ucsbplse.github.io/
- 主要语言
- Java
- 星标
- 2.2k
- 派生
- 396
- 平均合并
- 9 天 19 小时
- 30 天内合并 PR
- 3
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modesty/pdf2json 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 3/5 1-2 天 新手友好度 38/100
-
`getRawTextContent` does not returns words' pieces in proper coordinate order可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 48/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
help-wanted: type3-font not-supported
难度 4/5 3-5 天 新手友好度 42/100
相似的 Issue
-
bug build failed
难度 1/5 1 小时以内 新手友好度 91/100
objectionary/eo#9852 · 1 条评论 ·
维护者通常 2 天内回复
-
finsim-core good first issue
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
Require-Capability osgi.ee still says JavaSE 1.8 but classes are compiled for Java 11可能已有人在做 @arturobernalg 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
eclipse-ee4j/angus-mail#232 ·
维护者通常 3 天内回复
-
bug status: needs triage
难度 1/5 1-3 小时 新手友好度 78/100
LawnchairLauncher/lawnchair#7511 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 66/100
ahmedmmordi/store-app#11 ·