Skip to content
Skills Library
Documents & office · Conversion & formats

tool-pdf-extractor

/tool-pdf-extractor

Use as the first step whenever a user uploads a PDF document that needs text analysis, review, or RAG indexing. Extracts text from PDFs with a selectable text layer using PDF.js (fast, no OCR), preserving page boundaries, paragraph structure, headings, and tables for downstream citation. Falls back to OCR tools for scanned documents. Critical to get right — downstream analysis quality depends entirely on clean text extraction.

Licence
MIT
Last repository change
14.05.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 14.05.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Use as the first step whenever a user uploads a PDF document that needs text analysis, review, or RAG indexing. Extracts text from PDFs with a selectable text layer using PDF.js (fast, no OCR), preserving page boundaries, paragraph structure, headings, and tables for downstream citation. Falls back to OCR tools for scanned documents. Critical to get right — downstream analysis quality depends entirely on clean text extraction.

Original author description

Use as the first step whenever a user uploads a PDF document that needs text analysis, review, or RAG indexing. Extracts text from PDFs with a selectable text layer using PDF.js (fast, no OCR), preserving page boundaries, paragraph structure, headings, and tables for downstream citation. Falls back to OCR tools for scanned documents. Critical to get right — downstream analysis quality depends entirely on clean text extraction.

How it works

  1. What it does
  2. Library stack
  3. Extraction modes
  4. Output schema
  5. Critical design principles
  6. Language detection
  7. Multi-language documents (common in MENA)
  8. Failure modes
  9. Related skills
Original SKILL.md headings · 160 lines, 1,077 words
SKILL.md preview
---
name: tool-pdf-extractor
description: Use as the first step whenever a user uploads a PDF document that needs text analysis, review, or RAG indexing. Extracts text from PDFs with a selectable text layer using PDF.js (fast, no OCR), preserving page boundaries, paragraph structure, headings, and tables for downstream citation. Falls back to OCR tools for scanned documents. Critical to get right — downstream analysis quality depends entirely on clean text extraction.
license: MIT
metadata:
  id: tool.pdf-extractor
  category: tool
  priority: P0
  intent: [pdf-extract, parse-pdf, document-ingestion]
  related: [tool-ocr-arabic, tool-ocr-english, multimodal-scanned-pdf-handler, safety-pii-redaction-before-rag, tool-rag-firm-knowledge]
  source: Louis — HAQQ Legal AI (github.com/sboghossian/mini-claude-for-legal)
  version: "1.0"
---

# Tool — PDF Extractor

## What it does

The PDF Extractor is the entry point for all PDF documents entering the legal AI pipeline. It extracts text content, structure, and metadata from a PDF file, producing a clean, page-anchored text representation suitable for downstream analysis, RAG indexing, drafting reference, or review.

It is invoked automatically whenever a user uploads a PDF and a text-analysis task follows. The extractor decides whether the document has a native text layer (fast extraction) or needs OCR (slower, less accurate). Getting this decision right is critical: OCR on a PDF with a good text layer is wasteful; text extraction on a scanned PDF produces garbage.

## Library stack

| Library | Role | Notes |
|---------|------|-------|
| **pdfjs-dist** (Mozilla PDF.js) | Primary text-layer extraction | Browser + Node; fast; no server-side dependency |
| **pdfminer-six** (Python) | Fallback for complex layouts | Handles rotated pages, ligature correction |
| **Poppler (pdftotext)** | System-level fallback | Fastest for bulk extraction |
| **pdf2json** | JSON-structured extraction | Preserves font metadata for heading detection |

## Extraction modes

### Mode 1: Text-layer extraction (default)
For PDFs with a selectable text layer. This is the fastest path and produces the highest-quality output.

**When to use**: when clicking in the PDF lets you select and copy text — i.e., the PDF was created digitally (from Word, InDesign, etc.) rather than by scanning.

**Process**:
1. Open PDF with PDF.js
2. Extract text content per page with position metadata
3. Reconstruct reading order (left-to-right, top-to-bottom for LTR; right-to-left for RTL)
4. Detect heading candidates (larger font-size, bold, centered)
5. Detect clause/section numbering patterns
6. Detect definition blocks (terms in quotes or bold + definition)
7. Tag page boundaries
8. Return full-text + structure

### Mode 2: OCR fallback
For scanned PDFs where text-layer extraction returns < 50 characters per page.

**Routing**:
- Detect dominant language → route to [[tool-ocr-english]] or [[tool-ocr-arabic]]
- For bilingual documents → run both pipelines and merge by page

**Signal for scanned document**: average characters per page < 50 after text-layer extraction.

### Mode 3: Structured extraction
For documents where clause-level granularity is needed — e.g., a 50-clause MSA where the downstream task is clause-by-clause review.

**Additional steps**:
- Identify clause hierarchy (1, 1.1, 1.1.1; a, b, c; (i), (ii))
- Assign each clause its full hierarchical path
- Return as a nested clause tree

Output shape: `{ clauses: [{ path: "7.2.1", heading: "...", text: "...", page: 8 }] }`

### Mode 4: Table extraction
Tables are common in legal documents: schedules, pricing tables, IP registers, cap tables. PDF tables are structurally challenging — cells may not have borders and rely on spatial positioning.

**Process**:
- Detect table regions using line detection + cell spacing analysis
- Extract cell content row by row
- Return as: `{ tables: [{ page, rows: [[cell,...], ...], headers: [...] }] }`

## Output schema

```json
{
  "metadata": {
    "title": "Master Services Agreement",
    "author": "...",
    "created": "2025-03-01",
    "modified": "2025-03-15",
    "pages": 24,
    "language": "en",
    "encrypted": false,
    "textLayerPresent": true
  },
  "fullText": "MASTER SERVICES AGREEMENT\n\nThis Agreement...",
  "pages": [
    {
      "pageNum": 1,
      "text": "...",
      "headings": [{ "text": "RECITALS", "level": 1 }]
    }
  ],
  "structure": {
    "headings": [...],
    "clauses": [...],
    "definitions": [{ "term": "Confidential Information", "definition": "...", "page": 3 }],
    "tables": [...],
    "schedules": [{ "title": "Schedule 1 — Services", "page": 20 }]
  },
  "extractionMode": "text-layer",
  "qualityRating": "excellent",
  "warnings": []
}
```

## Critical design principles

### PII handling
Before the extracted text is sent to any LLM or RAG system, apply PII detection and — where required by firm policy or user consent settings — redact sensitive personal information. See [[safety-pii-redaction-before-rag]] for the redaction pipeline.

This is mandatory, not optional, for:
- Client-uploaded documents
- Documents containing national IDs, passport numbers, financial account details
- Medical or HR documents

### Page mapping preservation
Every text segment must carry its page number. This allows downstream skills to produce citations like "Clause 14.2 (p. 8)" rather than "somewhere in the document." Loss of page mapping is an anti-pattern — it undermines the tool's core value for legal work.

### Large file handling
Documents over 100 pages should be processed in 25-page batches to avoid memory exhaustion. Re-assemble results after all batches complete.

### Anti-patterns to avoid

| Anti-pattern | Why it's bad |
|---|---|
| Sending raw PDF bytes to LLM | Wastes context window; LLMs are not PDF parsers |
| OCR'ing a PDF that has a text layer | Slower; lower quality than native text |
| Stripping page boundaries | Makes citation impossible downstream |
| Ignoring language detection | Sends Arabic to English OCR → garbled output |
| Merging multi-language pages | Loses RTL/LTR context switching |

## Language detection

Before choosing extraction mode or OCR engine:
1. Extract a sample text block from the first page
2. Run language detection (langdetect or equivalent)
3. If Arabic → flag for RTL handling and OCR routing to [[tool-ocr-arabic]]
4. If French → flag for French-language RAG and analysis downstream
5. If mixed → note which pages are in which language

## Multi-language documents (common in MENA)

Many MENA legal documents are bilingual Arabic/English or Arabic/French. Handling:
- Extract each page separately
- Tag each page with its dominant language
- For interleaved bilingual text: split into language-tagged blocks
- Return a `bilingualSections` field indicating which pages are in which language
- Route each section to the appropriate downstream analysis tool

## Failure modes

| Failure | Symptom | Resolution |
|---------|---------|------------|
| Encrypted / password-protected | Error on open | Ask user to remove password; cannot extract |
| Corrupted PDF | Partial extraction / errors | Try alternative library (pdfminer fallback); warn user |
| Text layer garbage (font encoding error) | Gibberish characters | Try pdfminer with encoding detection; fall back to OCR |
| Scanned document mis-detected as text | Low-quality garbage text | Check chars-per-page threshold; trigger OCR fallback |
| Very large file (>500 pages) | Memory timeout | Chunk into 25-page batches; reassemble |
| Complex XFA forms | No text extracted | XFA requires dedicated form extractor; inform user |

## Related skills

- [[tool-ocr-arabic]] — OCR fallback for Arabic-language scanned pages
- [[tool-ocr-english]] — OCR fallback for English-language scanned pages
- [[multimodal-scanned-pdf-handler]] — higher-level orchestrator that routes scan types
- [[safety-pii-redaction-before-rag]] — apply before any LLM or RAG use of extracted text
- [[tool-rag-firm-knowledge]] — extracted text is indexed here for firm KB

Versions

The database has no other skills named tool-pdf-extractor.

Database snapshot: 13.11.2026 · package version 7aa01907600b (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100pdf-extractor
    This skill should be used when the user asks to "extract text from PDF", "convert PDF to text", "parse PDF", "read PDF contents", "extract data from documents", "batch PDF extraction", "PDF to markdown", "OCR PDF", "get text from PDF files", "I have a PDF", "can you read this…
  • 100pdf-extract
    Fast, zero-AI text extraction from PDFs that have a text layer (digitally created PDFs from Word, Typst, WeasyPrint, wkhtmltopdf, LaTeX, etc). Uses pymupdf - instant and deterministic. Use when you need to quickly pull raw text from a known text-layer PDF, e.g. "extract text…
  • 100processing-pdf
    Use when the user needs to extract data from PDFs, work with scanned documents, or manipulate PDF files. Triggers include: "extract text from PDF", "convert PDF to text/CSV/images", "scan/OCR this document", "merge/split/rotate PDF", "fill PDF form", "PDF is blank/empty" (likely…
  • 98pdf-structured-extractor
    Extract text, tables and images from PDF files into structured Markdown and CSV, preserving heading hierarchy and reading order. Handles two-column layouts; scanned and garbled pages are rendered to PNG for visual recognition instead of OCR (no Tesseract, no RapidOCR). Use when…
  • 100pdf-ocr
    Extract text from scanned PDFs using optical character recognition. Use when a user asks to OCR a PDF, read a scanned document, extract text from an image PDF, digitize a scanned file, convert a scanned PDF to text, or read text from a photograph of a document. Supports multiple…
  • 100document-processing
    This skill should be used when the user says \"process documents\", \"extract text from PDF\", \"OCR this document\", \"convert PDF to markdown\", \"extract emails from documents\", \"parse document\", \"document conversion\", \"batch OCR\", \"extract structured data from PDF\",…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.