Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 4.2 — PDFs, Scans and Tables
RAG and Vector Search · Example 1 of 2

Reading order on a two-column page

The positions are made up to show the idea. Real extractors report many small fragments per line, and column detection is a heuristic.

A PDF stores where each piece of text sits on the page, not what order to read it in, and a scanned page has no text at all. Tables lose their meaning when flattened. Each problem has a known fix.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Given the fragments [(50, 10, "Page 1"), (50, 50, "Return the bike"), (50, 70, "to any shop."), (50, 790, "Confidential")], write body_text(fragments, top, bottom) that keeps only fragments with top <= y <= bottom, sorts by y and joins the text with spaces. Print it with top=40, bottom=760.

02

Write row_sentences(header, rows) that returns one sentence per row in the form Plan: Day pass. Price: 12 dollars. and print them for the header ["Plan", "Price"] and the rows [["Day pass", "12 dollars"], ["Single ride", "4 dollars"]].

Explain it without notes

01

Why does text extracted from a two-column PDF often come out in the wrong order?

02

How do you find out that a page is a scan, and what do you do about it?

03

Why rewrite a table's rows as sentences before embedding?

04

How would you choose between two PDF extraction tools for your company's documents?

Reading order on a two-column page
Sign in to run this example in your browser.

Expected output

by line:   Lumen Bikes Handbook Shops open at 7 am A helmet is included and close at 9 pm every free with every rental. day. Riders under 16 must wear one. Page 3
by column: Shops open at 7 am and close at 9 pm every day. A helmet is included free with every rental. Riders under 16 must wear one.