getRawTextContent() returns the lines of every page in reverse order (bottom to top) since 4.0.3
まだ誰も着手していません。
評価
- 難易度
- 1/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 90/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, node.js
調査の方向性
lib/pdftextsorter.js を読み、issue で説明されている行のソートを調べてください。bidiTexts の y 座標がページの視覚的な順序とどう対応するかを確認し、次に提示された3行の再現例を実行して、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時間
- マージ済み PR(30日)
- 3
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
help-wanted: type3-font not-supported
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
modesty/pdf2json の issue をすべて見る
似ている issue
-
bug subsystem:agent-harness triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ShaftHQ/SHAFT_ENGINE#7797 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
NationalSecurityAgency/ghidra#10155 ·
メンテナーはふだん 2 日以内に返信
-
area:data coverage
難易度 1/5 1時間未満 初心者へのやさしさ 67/100
reacher-z/Awesome-CUA#4864 ·
メンテナーはふだん 19 日以内に返信
-
bug web-ui
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
jenkinsci/jenkins#27705 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
mod bug
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
elmital/FixMCStats#65 · コメント 3 件 ·