flowchart TD
subgraph Input["Source Documents"]
PDF[PDF File]
SCANS[Scanned Images]
end
subgraph Scholar["ai-scholar Package"]
INGEST[Ingestion]
OCR[OCR Agent]
SEG[Segmenter Agent]
TRANS[Translation Agent]
ANNOT[Annotation Agent]
end
subgraph PDAI["pdai Package"]
PAGES["pages/page_NNN/"]
MANIFEST["manifest.json"]
SEGMENTS["segments/"]
end
subgraph Viewer["ai-viewer Package"]
HTML[viewer.html]
UI[Interactive Viewer]
end
PDF --> INGEST
SCANS --> INGEST
INGEST --> PAGES
PAGES --> OCR
OCR --> PAGES
PAGES --> SEG
SEG --> MANIFEST
PAGES --> TRANS
PAGES --> ANNOT
TRANS --> PAGES
ANNOT --> PAGES
PAGES --> HTML
MANIFEST --> HTML
HTML --> UI
Three-Package Integration
Complete workflow across ai-scholar, pdai, and ai-viewer
Overview
The AI document processing ecosystem consists of three interconnected packages, each with a distinct responsibility:
| Package | Role | Primary Function |
|---|---|---|
| ai-scholar | Processing | OCR, segmentation, translation, annotation |
| pdai | Data | Structured document storage (page-centric) |
| ai-viewer | Presentation | Interactive web-based viewing |
This guide explains how they work together to transform PDFs into interactive, navigable documents.
Architecture
Package Responsibilities
ai-scholar: The Processing Engine
AI-Scholar transforms raw documents into structured, annotated content:
# Core processing commands
ai-scholar process document.pdf # PDF → pages/page_NNN/
ai-scholar segment ../pdai/DocName # → manifest.json
ai-scholar agent ../pdai/DocName translation-english # → pages/page_NNN/page_NNN_translation_english.xmlGenerates:
pages/page_NNN/page_NNN.png— High-resolution page imagespages/page_NNN/page_NNN.xml— Structured OCR output (DTD-validated)pages/page_NNN/page_NNN.html— Viewer-compatible HTMLpages/page_NNN/page_NNN_fig_M.png— Extracted figurespages/page_NNN/page_NNN_{agent}.xml— Agent processing outputsmanifest.json— Document structure and segment mappings
pdai: The Data Layer
PDAI provides a standardised, page-centric directory structure:
pdai/DocumentName/
├── DocumentName.pdf # Original source
├── manifest.json # Structure metadata
├── ai-orchestrator.yml # Agent configuration
├── css/ # Display styles
├── templates/ # Document-specific templates
├── pages/ # ALL page-level content
│ ├── page_000/
│ │ ├── page_000.png
│ │ ├── page_000.xml
│ │ ├── page_000.html
│ │ ├── page_000_translation_english.xml
│ │ └── page_000_fig_1.png
│ └── page_001/
│ └── ...
└── segments/ # Materialised segments
└── letters/
├── letter_000/
└── letter_001/
Key principle: All files for a page live together in pages/page_NNN/. No scattered directories.
ai-viewer: The Presentation Layer
AI-Viewer serves PDAI documents through an interactive web interface:
# Start server from project root
cd /path/to/2026project
python -m http.server 4100
# Open viewer
open "http://localhost:4100/ai-viewer/viewer.html?doc=pdai/DocumentName"Provides:
Interactive page navigation (Document mode)
Agent output viewing (Agent mode)
Segment-based browsing (letters, chapters, paragraphs)
MathJax rendering for mathematics
Translation layer selection
Complete Workflow
Step 1: Ingestion
Start with a PDF or folder of scanned images:
# From PDF
ai-scholar process ../pdai/E57/E57.pdf
# From scans folder
ai-scholar process ../scans/historical_doc/This creates the basic PDAI structure with page images in pages/page_NNN/.
Step 2: OCR Processing
Extract text from page images:
ai-scholar process ../pdai/E57 --model gemini-3-flash-previewGenerates pages/page_NNN/page_NNN.xml with structured content:
<page pidx="001">
<meta model="gemini-3-flash-preview" processed_date="2025-12-28"/>
<main>
<p><parno>1.</parno> Omnem mutationem quae...</p>
<p><parno>2.</parno> Huius generis effectus...</p>
</main>
<footnotes>
<footnote data-fn="1">Reference note...</footnote>
</footnotes>
</page>Step 3: Segmentation
Identify logical document structure:
ai-scholar segment ../pdai/E57Creates manifest.json with segment mappings:
{
"document": {
"name": "E57",
"title": "Inquisitio Physica...",
"page_count": 105,
},
"segments": {
"chapters": {
"items": [
{"id": "1", "number": 1, "title": "CAPUT PRIMUM", "pages": [1, 2, 3]}
]
},
"paragraphs": {
"items": [
{"id": "1", "number": 1, "pages": [1], "start_text": "Omnem mutationem..."}
]
}
}
}Step 4: Agent Processing
Run translation, annotation, or custom agents:
# Translate to English
ai-scholar agent ../pdai/E57 translation-english --pages 0-50
# Annotate entities
ai-scholar agent ../pdai/E57 annotate-entities --pages 0-50Outputs go to pages/page_NNN/page_NNN_{agent}.xml.
Step 5: Viewing
Serve the document with a simple HTTP server:
# Start from project root
cd /path/to/2026project
python -m http.server 4100
# Open browser
open "http://localhost:4100/ai-viewer/viewer.html?doc=pdai/E57"Navigate to explore:
Browse pages with images and HTML side-by-side (Document mode)
View agent outputs in three-pane layout (Agent mode)
Navigate by segment (chapter, paragraph)
Switch between translation layers
Agent Output Layers
The viewer can display different processing results.
Available Layers
After running agents, page folders contain multiple outputs:
pages/page_000/
├── page_000.png
├── page_000.xml
├── page_000.html
├── page_000_translation_english.xml
├── page_000_translation_german.xml
└── page_000_annotate_entities.xml
Viewing Layers
Document Mode:
- Use language dropdown to switch between Original, Deutsch, English
Agent Mode:
Select agent from navigator to view output
Compare source input with agent output side-by-side
Comparing Outputs
Original vs Translation — See how text was interpreted
Multiple translations — Compare English and German versions
Annotation overlays — View entity markup on original text
Cross-Package Commands
From ai-scholar
# Full processing pipeline
ai-scholar process document.pdf
ai-scholar segment ../pdai/DocName
ai-scholar agent ../pdai/DocName translation-english
# Migrate legacy documents
ai-scholar migrate ../pdai/DocName
ai-scholar migrate-all ../pdai
# Assessment
ai-scholar assess ../pdai/DocNameFrom Project Root
# Start server
cd /path/to/2026project
python -m http.server 4100
# View documents
open "http://localhost:4100/ai-viewer/viewer.html" # Home catalog
open "http://localhost:4100/ai-viewer/viewer.html?doc=pdai/E57" # Specific documentURL Structure
Viewer URLs
| URL | Description |
|---|---|
/ai-viewer/viewer.html |
Home catalog |
/ai-viewer/viewer.html?doc=pdai/E57 |
Document viewer |
/ai-viewer/viewer.html?doc=pdai/E57&page=10 |
Specific page |
/ai-viewer/viewer.html?doc=pdai/E57&mode=agent |
Agent mode |
Content URLs
| URL | Description |
|---|---|
/pdai/E57/pages/page_000/page_000.png |
Page image |
/pdai/E57/pages/page_000/page_000.html |
Page HTML |
/pdai/E57/pages/page_000/page_000_translation_english.xml |
Translation |
/pdai/E57/manifest.json |
Document manifest |
Document Discovery
Primary Source: pdai/index.json
The canonical document list:
{
"documents": [
{"name": "E57", "title": "Euler Tidal Theory", "pages": 105},
{"name": "Goldbach", "title": "Euler-Goldbach Letters", "pages": 483}
]
}Fallback: pdai-documents.json
Cached copy at project root for convenience.
Adding Documents
Process document with
ai-scholar processAdd entry to
pdai/index.jsonRefresh viewer — document appears in home catalog
Best Practices
Document Preparation
Process documents — Use
ai-scholar processfor new documentsMigrate old documents — Use
ai-scholar migratefor legacy documentsSegment early — Generate manifest.json for navigation
Validate structure — Use
ai-scholar assessto check integrity
Viewing Workflow
Start simple — View original HTML first
Check segments — Verify navigation works correctly
Add layers — Run translation/annotation agents as needed
Compare outputs — Switch layers to compare processing results
Troubleshooting
Document Not Loading
# Check structure
ls -la ../pdai/DocumentName/pages/page_000/
# Verify required files
ls ../pdai/DocumentName/pages/page_000/page_000.png
ls ../pdai/DocumentName/pages/page_000/page_000.htmlMissing Segments
# Run segmentation
ai-scholar segment ../pdai/DocumentName
# Check manifest
cat ../pdai/DocumentName/manifest.json | jq '.segments'Agent Outputs Not Showing
# Check page folder
ls ../pdai/DocumentName/pages/page_000/
# Run agent if missing
ai-scholar agent ../pdai/DocumentName translation-englishServer 404 Errors
# Ensure server runs from project root
cd /path/to/2026project # Parent of ai-viewer and pdai
python -m http.server 4100Summary
The three-package architecture provides clean separation of concerns:
ai-scholar handles all AI processing
pdai stores data in page-centric format
ai-viewer presents content interactively via static HTTP
Data flows from processing through storage to presentation, with all page-related files organised together in pages/page_NNN/ folders.