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 2 of 2

A table read two ways

The table is the new handbook document D13 (Price list). Its monthly pass row agrees with D8.

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?

A table read two ways
Sign in to run this example in your browser.

Expected output

column by column: Plan Single ride Day pass Monthly pass Price 4 dollars 12 dollars 25 dollars Includes up to 30 minutes unlimited rides of up to 30 minutes unlimited rides of up to 45 minutes
Plan: Single ride. Price: 4 dollars. Includes: up to 30 minutes.
Plan: Day pass. Price: 12 dollars. Includes: unlimited rides of up to 30 minutes.
Plan: Monthly pass. Price: 25 dollars. Includes: unlimited rides of up to 45 minutes.