markitdown icon indicating copy to clipboard operation
markitdown copied to clipboard

PDF: paragraph breaks inserted inside sentences (prose corrupted at arbitrary line gaps)

Open Gab-CosmoLabs opened this issue 3 months ago • 2 comments

Environment

  • markitdown 0.1.4 (CLI: markitdown input.pdf)
  • macOS 15 — reproduced on multiple official UAE government PDFs; deterministic per file

Summary

PDF → Markdown conversion inserts paragraph breaks inside sentences. The breaks do not correspond to paragraph boundaries in the source PDF — they fall at seemingly arbitrary line gaps within continuous prose. For LLM-ingestion use cases, paragraph breaks are semantic boundaries, so this silently corrupts the text.

Reproducer (official public PDF)

https://tax.gov.ae/Datafolder/Files/Pdf/2025/MD-No-229.pdf — UAE Ministerial Decision 229/2025, English column, 12 pages. Command: markitdown MD-No-229.pdf

Actual output (verbatim excerpts)

Title — a single running title in the PDF:

Qualifying Activities and Excluded Activities for the Purposes

of Federal Decree-Law No. 47 of 2022 on the Taxation of

Corporations and Businesses

Recital list — the continuation its amendments, starts lowercase, yet becomes its own paragraph:

–  Federal Decree-Law No. 47 of 2022 on the Taxation of Corporations and Businesses, and

its amendments,

Body prose — break inserted mid-sentence before a parenthetical:

distribution, warehousing, logistics or inventory management functions constitutes 51%

(fifty one percent) or more of their Revenue for the relevant Tax Period.

Expected output

Line wraps collapsed to continuous prose; paragraph breaks only at real paragraph boundaries:

Qualifying Activities and Excluded Activities for the Purposes of Federal Decree-Law No. 47 of 2022 on the Taxation of Corporations and Businesses

–  Federal Decree-Law No. 47 of 2022 on the Taxation of Corporations and Businesses, and its amendments,

distribution, warehousing, logistics or inventory management functions constitutes 51% (fifty one percent) or more of their Revenue for the relevant Tax Period.

Impact

Observed on 5+ official UAE MoF/FTA PDFs (legal texts). Splits are deterministic per file and land inside sentences every few paragraphs. Pipelines that treat the Markdown as structured text (LLM chunking, diffing, citation anchoring) inherit corrupted sentence boundaries.

Relationship to existing issues

Not covered by #83 (text relationship/indentation), #293 / #1419 (tables), or #45 (formulas) — this is plain prose in text-heavy PDFs; no tables, formulas, or markers involved.

Happy to provide additional sample files.

Gab-CosmoLabs avatar Sep 02 '26 21:09 Gab-CosmoLabs

@/tmp/comment2370.md

NG-PR0JECT avatar Sep 08 '26 06:09 NG-PR0JECT

I'd like to fix this. pdfminer groups lines into text boxes and separates boxes with a blank line. When a PDF's line spacing is close to LAParams.line_margin (0.5), one paragraph is split into several boxes, so blank lines land mid-sentence. The repo's own fixtures show it (masterformat_partial_numbering.pdf: "in the format\n\ndetailed in this document"; the SPARSE expected output: "should be\n\nreviewed").

My plan is implement a small post-processing step next to _merge_partial_numbering_lines that removes a single blank line only when the previous line does not end a sentence and the next line starts in lowercase (list items and page breaks untouched). I'd rather not change line_margin globally, since that would regroup every PDF. Tests included.

mert-ogul avatar Nov 11 '26 23:11 mert-ogul