Turn PDFs and Office files into RAG chunks with the tables intact (HTTP Request + Apify)

When PDFs go into a RAG pipeline, the tables are usually what breaks: most PDF-to-text steps turn a borderless financial table into a column of loose numbers, and the model then answers about the wrong row.

This workflow sends file URLs (PDF, Word, PowerPoint, Excel, images) to an Apify Actor I built, Document to Markdown, through a plain HTTP Request node, so it works on n8n Cloud without community nodes. You get:

  • PDF tables, with or without lines, as Markdown tables
  • scanned pages through OCR, rebuilt as paragraphs, lists and headings
  • each file split into chunks with pageStart, pageEnd and the nearest heading

The last Code node emits one n8n item per chunk (text, source, pageStart, heading), ready for an embeddings node and a vector store, so answers can cite the page.

Setup: create a Header Auth credential (Authorization = Bearer YOUR_APIFY_TOKEN), put your file URLs in Configure, run. It costs $2 per 1,000 pages ($5 per 1,000 OCR pages) on Apify, and runs on CPU.

On four public test PDFs, the borderless tables came out with the same rows as an ML converter that took 13 minutes for the same files; here it was 16 seconds. I wrote up what it took to get there: the write-up. Merged header cells still come out as empty cells, and tables inside scanned pages come out as text.

Workflow JSON (paste onto an empty canvas)

Feedback welcome, especially on PDFs where the tables still break.

1 Like

The page + heading metadata on every chunk is a great touch for citations. On the merged header cells: one trick is to fill the merged value across the columns it spans and join it with the sub-header, so “Revenue” over “2025 | 2026” becomes “Revenue 2025 | Revenue 2026”. The model never sees an empty header. And if a long table gets split across chunks, repeating the header row in each one helps a lot. Does the chunker keep tables whole right now?

hey, How does it behave on a 200+ page scanned PDF with OCR?

@saliga, the scanned-table limitation you mentioned is an important RAG test case. A correct page citation can still accompany a value taken from the wrong column.

Building on the header/chunking suggestion above, I would test one table with two year columns and three labelled rows. Keep a small reference set of (row label, year, value, page), then compare those associations after extraction and chunking before testing retrieval. For example, ask for the same row in 2025 and 2026 separately; both the number and its year/row association must match. This distinguishes extraction errors from retrieval errors.

If merged-header span information has already been lost, filling every blank header forward could invent associations. I would flag those tables for review rather than infer the missing structure silently.

Do you have a public PDF and its emitted chunk JSON showing one of these failures? I can help turn one example into a small reproducible regression test for the n8n-to-vector-store step.

Thanks all, and sorry for the slow reply.

@mahathir_lol Yes: with chunking on, tables aren’t cut mid-row. A big table is split between rows, and the header row is repeated in each chunk. Merged header cells are the weak spot: right now they come out empty. Filling the spanned value across (“Revenue 2025 | Revenue 2026”) is a good idea. I’d only do it when the PDF actually tells us the span, which ties into Saim’s point below.

@Kashish_Rathore1 OCR only runs on pages with no text layer, and it costs $5 per 1,000 pages, so 200 scanned pages is about $1. I haven’t timed a 200-page scan yet. The workflow above uses the run-sync endpoint, which waits at most 5 minutes. For long scans I’d start the run asynchronously and fetch the dataset when it finishes, or cap it with maxPages. Also, tables inside scanned pages come out as text, not as tables.

@saim14 Agreed: a correct page number next to a value from the wrong column is the worst case, because it looks trustworthy. If the span of a merged header can’t be read from the PDF, I’d rather leave it empty than guess. I don’t have a public failing PDF with its chunk JSON yet; when I find one, I’ll post it here.

1 Like