1
Step 2 Read the PDF
Tirsvad edited this page 2026-11-20 15:52:38 +01:00

English · Dansk · Bahasa Malaysia

Step 2: Read the PDF

Step 2: read the PDF and split the text

What we did

  • extract_text_from_pdf reads every page with pypdf and joins the page texts.
  • split_text_into_chunks cuts the text at paragraph and sentence ends into pieces of at most 400 characters (MAX_CHUNK_CHARS), never in the middle of a word.
  • A PDF with no text (for example a scan) gives a clear PdfTextError instead of silence.
python tools/demo_extract.py tests/data/sample.pdf

What we gained

  • Speech engines work best with short pieces of text, so chunking is a real business rule, and it lives in the domain layer with no input or output.
  • Tests need no binary files: a small standard-library function builds a valid PDF on the fly.
  • Errors are named for what went wrong, and the original cause is kept with raise ... from.