getRawTextContent() returns the lines of every page in reverse order (bottom to top) since 4.0.3
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 90/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js
Research direction
Read lib/pdftextsorter.js and inspect the line sort described in the issue. Check how the bidiTexts y coordinates relate to visual page order, then run the supplied three-line reproduction and verify getRawTextContent() emits First, Second, Third line in that order, followed by the page break.
Written by the indexing model from the issue text.
Description
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/
- Dominant language
- Java
- Stars
- 2.2k
- Forks
- 396
- Avg merge
- 9d 19h
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modesty/pdf2json
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
-
`getRawTextContent` does not returns words' pieces in proper coordinate orderPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
help-wanted: type3-font not-supported
Difficulty 4/5 3-5 days Newbie friendliness 42/100
All issues in modesty/pdf2json
Similar issues
-
bug subsystem:agent-harness triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ShaftHQ/SHAFT_ENGINE#7797 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
NationalSecurityAgency/ghidra#10155 ·
Maintainers usually reply within 2 days
-
area:data coverage
Difficulty 1/5 Under an hour Newbie friendliness 67/100
reacher-z/Awesome-CUA#4864 ·
Maintainers usually reply within 19 days
-
bug web-ui
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
jenkinsci/jenkins#27705 · 3 comments ·
Maintainers usually reply within 1 day
-
mod bug
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
elmital/FixMCStats#65 · 3 comments ·