A 90-row table printed to PDF lands on three pages. Convert it to Markdown and you get three tables, each with its own header row, or worse, with row 34 sitting in the header slot because page 2 didn't repeat the header. Chunk that for retrieval and each chunk holds a third of the table, two of them with column names that aren't column names.
People keep asking for the fix. On docling, "Continued table across pages is split into multiple tables" is open with 11 comments and a priority:medium label; the expected result in it is "The full table (including rows from both pages) should be merged into a single structured table." An older docling issue proposes merging with an LLM, because "tables that are visually contiguous get split during conversion". Both were active as of Nov 16, 2026. On pymupdf4llm the maintainer answered the same request by saying the library can't recognise a continuation and that merging is post-processing (April 2025). Marker has the opposite complaint: it merges tables on consecutive slides that should stay apart. And the Stack Overflow question "Extracting tables spanning to multiple pages" has 18,000 views.
So I ran three converters on tables that cross pages: pdf2md (the one we make), markitdown and pymupdf4llm. None of them merges. pdf2md has a worse problem on one kind of table, and on the real document below it lost to markitdown completely.
The test
Fixtures. Nine generated PDFs, each with a numbered Row column so every row can be counted:
- six from reportlab: a 4-column parts list, 70 rows over 3 pages, ruled or plain, header repeated on each page or not, plus one file with two genuinely separate tables on two pages, which must stay two;
- three printed by Chromium with Playwright's
page.pdf()from an HTML table, 90 rows over 3 pages: header in<thead>(Chromium repeats it on every page), header as an ordinary first row (printed once), and a packed, left-aligned version.
A real document. IRS Publication 15-T (2026), pages 14 to 27: the wage-bracket tables for manual payroll. That's five tables (weekly, biweekly, semimonthly, monthly, daily), each two or three pages long, eight amounts per row, header repeated on every page. 799 rows in all. A row counts as intact only when all eight amounts sit in one Markdown table row, which is the only shape a reader or an LLM can use: "$785 to $795, married filing jointly, standard withholding: $17".
Tools: @dudko.dev/pdf-to-md-cli 0.3.6 with default options, markitdown 0.1.9 (pip install 'markitdown[pdf]'), pymupdf4llm 2.2.
Results
The page breaks first. On every fixture where a tool kept the columns, it produced one table per page:
| pdf2md 0.3.6 | markitdown 0.1.9 | pymupdf4llm 2.2 | |
|---|---|---|---|
| 3-page table → Markdown tables | 3 (2 on two files) | 3 | 3 |
| header repeated in the PDF | repeated in the Markdown | repeated | repeated |
| no header on page 2 | first data row becomes the header | same | same |
| two separate tables stay two | yes | yes | yes |
Nobody merges, and nobody has an option to. On the reportlab file with no repeated header, all three put R027 | Part 027 bracket | … in the header row of the second table. pdf2md did join pages 2 and 3 of the packed left-aligned tables (both generators) and dropped the repeated header, but not pages 1 and 2. That's inconsistent, not a feature to rely on.
Then the columns, which is where the tools really differ:
| rows with all 4 cells in one table row | pdf2md | markitdown | pymupdf4llm |
|---|---|---|---|
| reportlab, numbers right-aligned, wide gap (4 files) | 0 of 70 | 70 of 70 | 70 of 70 |
| reportlab, packed, left-aligned | 70 of 70 | 0 of 70 | 70 of 70 |
Chromium, <thead>, right-aligned | 90 of 90 | 90 of 90 | 90 of 90 |
| Chromium, header printed once | 90 of 90 | 90 of 90 | 90 of 90 |
| Chromium, packed, left-aligned | 90 of 90 | no table | 90 of 90 |
pdf2md cuts some tables into column strips. On the four reportlab files with right-aligned numbers and a wide gap before them, every page came out as two 2-column tables, Row | Item and then Qty | Unit price: six tables for three pages, and no row with its quantity and price next to it. A one-page probe narrows it down a little. With 8 rows the table stays whole; at 12, 16, 20 and 25 rows it splits, whether the numbers are right-aligned, the gap is wide, or both. Only the packed, left-aligned layout stayed whole at every height. --profile compact changes nothing. The Chromium-printed table with right-aligned numbers did not split, so alignment alone isn't the trigger, and I can't tell you exactly what is.
markitdown has its own failures on packed tables. On the reportlab one it glued quantity and price into one cell (4 36.70). On the Chromium one it found no table at all and wrote each column as a run of separate paragraphs.
The IRS tables
| pdf2md | markitdown | pymupdf4llm | |
|---|---|---|---|
| intact rows (all 8 amounts in one row) | 0 of 799 | 799 of 799 | 62 of 799 |
| Markdown tables for 14 pages (5 real tables) | 27 | 42 | 14 |
table lines with <br> (rows glued together) | 0 | 0 | 609 |
| dollar amounts in the output (PDF has 6,392) | 6,392 | 6,392 | 6,386 |
pdf2md read each page as two tables: a 3-column strip with the bracket and the first withholding column, and a 5-column strip with the other five amounts and no bracket at all. That's the picture at the top of this page. Every number is in the output, in the wrong shape: the second strip is five columns of dollar amounts with nothing to say which wage they belong to. For this document pdf2md's Markdown is unusable, and markitdown's is the one to take.
markitdown kept every row whole. It also wrote the page furniture as tables (the IRS proof line "Page 14 of 71 … 15:14 - 3-Dec-2025", the column-group headings), which is why there are 42 tables. pymupdf4llm kept most of the numbers but packed several brackets into one cell with <br>.
One more thing about pdf2md, and it matters for any script that works page by page: with --page-markers a 3-page table got one <!-- Page N --> marker, for page 1. The two-page file with two separate tables got two. If you count markers to find page boundaries, a long table hides them.
Merging the per-page tables
When the converter kept the columns, the fix is mechanical. Walk the tables in order and append table B to table A when:
- they have the same number of columns;
- nothing stands between them, or only the same lines that stood above A (a running page head, compared with digits masked so "Page 2" equals "Page 3");
- B's header row is A's header again, which gets dropped, or B's "header" is a data row the converter promoted, which goes back into the body. To tell a promoted row from a different table's header, its cells must have the same kinds (number, text, text with digits) as A's last row.
The third check is what stops the script from gluing pdf2md's strips back together in the wrong order: Qty | Unit price is words, and R023 | Part 023 bracket isn't, so they stay apart. Condition 2 is what keeps marker's slide case apart: a heading between two tables blocks the merge.
#!/usr/bin/env python3 """Join Markdown tables that a PDF converter split at page breaks. Usage: python merge_tables.py in.md > out.md (what it merged goes to stderr)""" import re import sys def cells(line): return [c.strip() for c in line.strip().strip("|").split("|")] def is_sep(line): return bool(re.fullmatch(r"\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)*\|?", line.strip())) def norm(line): # compare text, not padding, bold or page numbers return " ".join(re.sub(r"\d+", "#", c.replace("*", "")) for c in cells(line) if c) def shape(line): # per cell: empty, number, text with digits, or words only def one(c): c = c.replace("*", "") if not c: return "" if re.fullmatch(r"[-+$€£(]*[\d.,]+%?\)?", c): return "n" return "a9" if re.search(r"\d", c) else "a" return [one(c) for c in cells(line)] def blocks(md): out, table = [], None for line in md.splitlines(): if line.lstrip().startswith("|"): if table is None: table = {"kind": "table", "lines": []} out.append(table) table["lines"].append(line.rstrip()) continue table = None if not line.strip() or re.fullmatch(r"\s*<!--.*-->\s*", line): continue # blank lines and page markers separate nothing out.append({"kind": "text", "lines": [line.rstrip()]}) return out def key(block): return " / ".join(norm(l) if block["kind"] == "table" else re.sub(r"\d+", "#", l.strip()) for l in block["lines"]) def merge(md, log=lambda m: None): bl = blocks(md) result = [] # blocks after merging head = {} # id(table in result) -> index in bl where its chain began i = 0 while i < len(bl): b = bl[i] if b["kind"] != "table" or len(b["lines"]) < 2 or not is_sep(b["lines"][1]): result.append(b) i += 1 continue # the last table already in result, and what lies between it and b k = len(result) - 1 while k >= 0 and result[k]["kind"] != "table": k -= 1 a = result[k] if k >= 0 else None gap = result[k + 1:] if a else [] if a and len(cells(a["lines"][0])) == len(cells(b["lines"][0])): start = head.get(id(a), 0) above = bl[max(0, start - len(gap)):start] if not gap or [key(g) for g in gap] == [key(g) for g in above]: rows = b["lines"][2:] same_header = norm(b["lines"][0]) == norm(a["lines"][0]) # not the same header: join only if B's first row looks like A's rows promoted = not same_header and len(a["lines"]) > 2 and \ shape(b["lines"][0]) == shape(a["lines"][-1]) if same_header or promoted: if promoted: rows = [b["lines"][0]] + rows a["lines"].extend(rows) del result[k + 1:] # the repeated page head goes too log(f"joined {len(rows)} rows onto the table above") i += 1 continue result.append(b) head[id(b)] = i i += 1 return "\n\n".join("\n".join(x["lines"]) for x in result) + "\n" if __name__ == "__main__": text = open(sys.argv[1], encoding="utf-8").read() sys.stdout.write(merge(text, log=lambda m: print(m, file=sys.stderr))) npx @dudko.dev/pdf-to-md-cli parts.pdf > parts.md # or: markitdown parts.pdf > parts.md python merge_tables.py parts.md > parts.merged.md It rewrites the whole file with one blank line between blocks, so run it on converter output, not on hand-edited Markdown you care about the spacing of.
What it did, measured on the same outputs:
after merge_tables.py | pdf2md | markitdown | pymupdf4llm |
|---|---|---|---|
| fixtures where the columns survived | 1 table each, every row in order | 1 table each | 1 table each |
| two separate tables | still 2 | still 2 | still 2 |
| pdf2md's column strips | left alone (6 stay 6) | ||
| IRS pages, 5 real tables | 27 (no joins) | 42 (no joins) | 13 (one join) |
On the fixtures it does the job, for every tool, including the pages where the first data row had been promoted to header. On the IRS output it does almost nothing, and the reason is worth knowing. markitdown's table for page 14 has 9 columns and the one for page 15 has 12, with empty spacer columns in different places, and the page footer ("14 … Publication 15-T (2026)") is a row inside the table. The column count check refuses, correctly: a Markdown-level merge can only join tables that came out the same shape. Real documents often don't.
When the table is the point: read it from the PDF
For a table like the IRS one, where every row has a known shape, I'd skip Markdown conversion for those pages and read the rows from the PDF directly. pdfplumber's text extraction keeps each bracket on one line. Loop over the pages, collect the lines that match the row shape, start a new table when the section heading changes, and check that nothing fell out at a page break. Here the brackets are contiguous, so each row's "at least" has to equal the previous row's "but less than":
#!/usr/bin/env python3 """The wage-bracket tables of IRS Publication 15-T as Markdown, one table per payroll period, however many pages each one runs over. Usage: python wage_tables.py p15t.pdf [first_page last_page] > tables.md""" import re import sys import pdfplumber AMT = r"\$[\d,]+(?:\.\d\d)?" ROW = re.compile(rf"(?:{AMT} ){{7}}{AMT}") # a bracket: 8 amounts PERIOD = re.compile(r"^(\w+) Payroll Period$", re.M) HEAD = ["At least", "But less than", "MFJ standard", "MFJ Step 2 checkbox", "HoH standard", "HoH Step 2 checkbox", "Single/MFS standard", "Single/MFS Step 2 checkbox"] def read(pdf_file, first=1, last=None): tables = {} # period name -> rows, in document order with pdfplumber.open(pdf_file) as pdf: for n, page in enumerate(pdf.pages[first - 1:last], start=first): text = page.extract_text() or "" m = PERIOD.search(text) if not m: continue rows = tables.setdefault(m.group(1), []) for line in text.splitlines(): if not ROW.fullmatch(line.strip()): continue cells = line.split() # brackets are contiguous: this row starts where the last one ended if rows and rows[-1][1] != cells[0]: print(f"page {n}: gap between {rows[-1][1]} and {cells[0]}", file=sys.stderr) rows.append(cells) return tables def markdown(tables): out = [] for period, rows in tables.items(): out.append(f"## {period.capitalize()} payroll period\n") out.append("| " + " | ".join(HEAD) + " |") out.append("|" + "---|" * len(HEAD)) out += ["| " + " | ".join(r) + " |" for r in rows] out.append("") return "\n".join(out) if __name__ == "__main__": pages = [int(x) for x in sys.argv[2:4]] tables = read(sys.argv[1], *pages) for period, rows in tables.items(): print(f"{period}: {len(rows)} rows", file=sys.stderr) sys.stdout.write(markdown(tables)) pip install pdfplumber curl -sSLO https://www.irs.gov/pub/irs-pdf/p15t.pdf python wage_tables.py p15t.pdf 14 27 > wage-tables.md Result: five tables (178, 178, 184, 185 and 74 rows), 799 of 799 rows intact, one header each, and no gap reported at any page break. It's specific to this document, and that's the point: when you know the row shape, a 40-line script beats any general converter, ours included. The same loop works for bank statements and price lists with a different ROW pattern and a different continuity check (a running balance, a sorted SKU).
What I'd do
- Multi-page tables in mostly-prose documents (reports, contracts with schedules): convert with whatever handles the prose well, then run
merge_tables.py. It's cheap, it leaves separate tables alone, and it tells you on stderr what it joined. - Wide numeric tables over many pages (tax tables, statements, rate cards): don't use pdf2md for those pages today. On the IRS document markitdown kept every row and pdf2md kept none. Better still, read the rows with pdfplumber as above, and convert the prose around them with whichever tool you like.
- Check before you trust it. A cheap test on any converter's output: count the tables per page and their columns. If a page has two tables whose column counts add up to the header you expected, the table was cut into strips, and no merge after the fact will put it back.
pdf2md has no table-merging option, and these measurements are of its npm CLI. The same parser runs in the browser at pdf2md.dudko.dev/app, where nothing is uploaded, and over an HTTP API; I didn't run these files through the API. pdf2md does no OCR, so a scanned table needs OCR first (which pages need it). The packages are free for noncommercial use under PolyForm Noncommercial 1.0.0, with a 32-day trial for evaluating at work.
The HTML fixture
The Chromium-printed tables come from this script. npm i playwright && npx playwright install chromium, then node make_html_fixture.mjs out writes the three PDFs.
// make_html_fixture.mjs: a 90-row table printed to PDF by Chromium, three ways import { chromium } from 'playwright'; import { mkdirSync } from 'node:fs'; const out = process.argv[2]; mkdirSync(out, { recursive: true }); const rows = Array.from({ length: 90 }, (_, k) => { const i = k + 1; return [`R${String(i).padStart(3, '0')}`, `Part ${String(i).padStart(3, '0')} bracket`, String(i % 7 + 1), ((i * 3.17) % 90 + 5).toFixed(2)]; }); const head = ['Row', 'Item', 'Qty', 'Unit price']; const tr = (r, tag = 'td') => `<tr>${r.map((c, j) => `<${tag}${j >= 2 ? ' class="n"' : ''}>${c}</${tag}>`).join('')}</tr>`; const css = (align, width) => `body{font:11pt Helvetica,Arial,sans-serif;margin:0} table{border-collapse:collapse;width:${width}} td,th{border:1px solid #444;padding:4px 8px;text-align:left} th{font-weight:bold} .n{text-align:${align}}`; const variants = { html_thead_right: { thead: true, align: 'right', width: '100%' Source:https://dev.to/dudko-dev/a-pdf-table-that-spans-pages-comes-out-as-one-markdown-table-per-page-merging-it-back-e0d Related posts

Roads, gates and walk-in halls in a browser cultivation game
ByeMoney è l’app Android per le spese di casa: AI 100% offline per scontrini e voce, dati solo sul tuo Google Sheet, zero abbonamenti. Presto su Google Play. Scrivimi se vuoi provarla come tester! htt
Picking a URL shortener in 2026 as an EU team: five compared
Migrating Short Links Off Bitly Without Breaking QR Codes
