# Documents, files and media

Most of what an agent is asked to read is not a web page. CrawlGenie reads these without a model, on the server, and returns text or the passages that answer a question.

## What is supported

| Source | How CrawlGenie reads it | Notes |
|---|---|---|
| PDF with a text layer | pdf.js text extraction, lines rebuilt by position, **tables rebuilt into pipe rows** when a page looks tabular | `pages: "1-5,9"` to read only some pages (1-based); `## Page N` headings in the output |
| Scanned PDF / PDF without text | **OCR**: pages are rendered on the server and read with Tesseract (`ocr: auto` when the text layer is empty or sparse; `ocr: force` to insist; `ocr: off`) | Confidence is reported; English + script auto-detect; first run downloads language data into `data/tesseract` |
| Images (PNG, JPEG, WEBP, GIF, BMP) | OCR | Token savings, screenshots, scanned letters, slides exported as images |
| DOCX, XLSX, PPTX | Zip + XML parsing (no Office needed) | Sheets become rows; slides become `## Slide N` sections |
| ODT, ODS, ODP (LibreOffice / Google export) | Zip + `content.xml` | Headings, tables and slides preserved |
| RTF | Control-word stripping | Legacy contracts and letters |
| TXT, CSV, Markdown, JSON, XML | As text | |
| HTML files | Tags stripped | Prefer `/v1/scrape` for live pages (readability + boilerplate removal) |
| **Google Docs / Sheets / Slides** (public or "anyone with the link") | The link is rewritten to the export endpoint: Docs → text, Sheets → CSV (the selected tab), Slides → PDF | No Google API key; private files need the owner to share the link |
| Google Drive / Dropbox share links | Rewritten to direct download | |
| GitHub `blob` links | Rewritten to the raw file | |
| **YouTube** | Caption track (manual or auto-generated) → timestamped paragraphs; falls back to the transcript panel | No speech model; videos without captions return "no transcript" |
| Audio / video files | Not transcribed | Listed by `page_media` so you can route them elsewhere |

## OCR: what it is and when it runs

OCR (optical character recognition) turns pixels into characters. A scanned invoice is a picture; it has no words a program can read until OCR runs. CrawlGenie renders each PDF page (or takes the image), runs Tesseract on the server, and keeps the text with a confidence score. It is slower than reading a text layer (about 1–3 s per page on a laptop) and it is never sent to a third party. Use `ocr: auto` (default) and let CrawlGenie decide; use `force` for PDFs whose text layer is garbage (common with faxes and some printers).

## Calls

```bash
# a document by URL (PDF/Office/Google Doc/image/YouTube), optional question and page range
curl -X POST $CRAWLGENIE/v1/parse -H "Authorization: Bearer $KEY" -H "content-type: application/json" \
  -d '{"url":"https://example.com/annual-report.pdf","q":"revenue by segment","pages":"30-60"}'

# a local file (base64) — the Playground drop zone does this for you
curl -X POST $CRAWLGENIE/v1/parse -H "Authorization: Bearer $KEY" -H "content-type: application/json" \
  -d '{"base64":"<...>","filename":"invoice.png","ocr":"auto","redactPII":true}'

# /v1/scrape routes documents automatically, so agents can use one call for pages and files
curl -X POST $CRAWLGENIE/v1/scrape -H "Authorization: Bearer $KEY" -H "content-type: application/json" \
  -d '{"url":"https://docs.google.com/spreadsheets/d/<id>/edit#gid=0","q":"total for March"}'

# several sources, one question
curl -X POST $CRAWLGENIE/v1/answer -H "Authorization: Bearer $KEY" -H "content-type: application/json" \
  -d '{"urls":["https://a.com/pricing","https://b.com/pricing.pdf"],"q":"price per seat per month"}'
```

From MCP / connectors the same happens through `web_answer` (one URL), `web_research` (search, or `urls` to compare), `knowledge_add` (keep it), and the `youtube_transcript`, `page_media`, `llms_txt` extractors.

## Reading less: `q`, `granularity`, `maxTokens`, `pages`

- `q` keeps only the passages that match the question (BM25 with phrase and heading bonuses). The response carries `focus.tokensFull` vs `focus.tokensFocused`.
- `granularity: "sentence"` returns only the matching sentences, table rows and code lines, grouped under their headings. Use it when the answer is one line (a price, a date, a limit).
- `maxTokens` cuts with the real tokenizer so a tool result never overflows a budget.
- `pages` avoids parsing a 400-page PDF to answer from the appendix.
- **Outline first** (`page_outline`, `POST /v1/read/outline`): for a long page or document when you do not know the question yet. You get one line per section with its size and first sentence (Wikipedia's 58,046-token "Python" article became a 1,176-token outline), then `read_sections` returns only the sections you pick, from the same copy.
- **JSON and API answers** read with `web_answer` come back as a compact table of their records, nested fields as dotted columns (npm search, 10 records: 3,877 tokens of JSON → 924).

## Privacy: `redactPII`

`redactPII: true` on `/v1/parse`, `/v1/scrape` and `web_answer (redact_pii)` replaces emails, phone numbers, card numbers (Luhn-checked), IBANs, US SSNs and public IPv4 addresses with placeholders *before* the text leaves CrawlGenie, and reports counts. Names and street addresses are not detected (that needs a model); say so to your compliance team rather than assume.

## Files attached inside ChatGPT or Claude

The CrawlGenie Chrome extension makes them smaller: a PDF, Word, PowerPoint or Excel file you attach on chatgpt.com or claude.ai goes in as its text plus pictures of only the charts, photos and figures. It runs on your computer, needs no key and sends nothing to CrawlGenie.

- **PDF:** every page as text, tables kept as rows, and a cropped picture of each page that draws something text cannot carry (a chart, a diagram, a photo, a scanned page). A PDF that is mostly pictures goes in as it is.
- **Word:** headings, lists, tables and footnotes as text; each photo attached and marked where it sits.
- **PowerPoint:** slides in order with their titles, tables, the numbers behind each chart, diagram text and speaker notes; pictures attached.
- **Excel:** each sheet as CSV with the values the cells show (formula results, dates as dates) and the Excel row numbers. A very large workbook goes in as it is, because the chat's own code tool reads those better.

ChatGPT gets each picture separately when there are a few, and one sheet of labelled pictures when there are many, because it limits attachments. Your connector never sees a chat attachment. For a file at a link, your AI can also hand the link to CrawlGenie (`web_answer`, `/v1/parse`) and get only the passages that answer.
