# Scanned insurance policy PDF OCR workflow

Use when Drive/downloaded policy PDFs appear to have no usable text layer (e.g. `pdftotext` output is 1–2 bytes or mostly blank).

## Workflow

1. Download/copy PDFs to a task-local working directory; keep originals unchanged.
2. Try text extraction first:
   ```bash
   pdftotext -layout input.pdf output.txt
   wc -c output.txt
   ```
3. If extraction is empty/minimal, run OCR with a sidecar text file:
   ```bash
   mkdir -p ocr ocr_text
   ocrmypdf -l deu+eng --rotate-pages --deskew --skip-text \
     --sidecar ocr_text/name.txt input.pdf ocr/name_ocr.pdf
   ```
4. Read the sidecar text, not just the OCR PDF, and extract structured fields: policy number, dates, premiums, sums insured, deductibles, AVB editions, discounts, special conditions, and caveats.
5. In the final artifact, mark OCR-derived values as extracted from scanned PDFs and avoid overclaiming if OCR noise remains.

## Pitfalls

- Many insurer PDFs are image-only despite looking like generated PDFs.
- OCR may confuse apostrophes, umlauts, columns, and CHF amounts; cross-check totals across the cover letter and line-item pages.
- For insurance tasks, preserve page/section names in notes so the user can challenge the insurer with exact wording.
