PDF files: read, fill, create

Extracts text and tables, merges, splits, encrypts and OCRs PDFs with pypdf, pdfplumber, reportlab and qpdf, and fills forms through bundled scripts that check fields and boxes. Use when a task reads, fills or produces a PDF file.

DocumentationPack: Anthropic skills314 linespdf
Author
Source
anthropics/skills/skills/pdf @ e4bb5d9
License
Apache-2.0

About this skill

What it does

SKILL.md maps each PDF job to a Python library or command-line tool: pypdf to merge, split, rotate, watermark and encrypt; pdfplumber for text and tables, which can go through pandas into Excel; reportlab for new PDFs; pytesseract over pdf2image for OCR; pdftotext, pdfimages and qpdf in the shell. It warns that reportlab's built-in fonts draw Unicode subscripts as black boxes. REFERENCE.md adds pypdfium2, the JavaScript libraries pdf-lib and pdfjs-dist, qpdf repair and batch processing.

Form filling, in FORMS.md, is the strict part. The agent first runs scripts/check_fillable_fields.py. A PDF with real fields goes through extract_form_field_info.py, page images from convert_pdf_to_images.py and fill_fillable_fields.py, which rejects unknown field IDs and values. A flat form gets text annotations: extract_form_structure.py pulls labels, lines and checkboxes with coordinates, or, for a scan, the agent estimates positions from page images and refines them on ImageMagick crops. check_bounding_boxes.py catches overlapping or too-small boxes before fill_pdf_form_with_annotations.py writes the text, and the agent checks the rendered result. create_validation_image.py draws the boxes on a page image; FORMS.md does not call it.

When to use it, and when not

Use it to extract text or tables, merge or split files, fill a form, OCR a scan or generate a PDF from data.

Beyond reportlab examples there is no layout guidance, so a formatted document people will also edit is better built in Word. No API keys; it needs pypdf, pdfplumber, reportlab, pdf2image, Pillow and Poppler, plus Tesseract for OCR and ImageMagick for scanned forms.

How to run it

The install command below puts the whole folder in place: SKILL.md, FORMS.md, REFERENCE.md, eight scripts and the licence. The agent picks the skill up whenever a PDF comes up; to call it yourself:

  • Claude Code: /pdf, or ask for the skill by name.
  • Codex: $pdf.
  • Cursor: type / in the Agent chat and pick pdf.

Example: /pdf Fill in form.pdf with the data from applicant.json and show me the filled pages.

How it differs from similar skills

No other pack in our catalog has a PDF skill, so the pdf folder name is not taken twice. Its neighbours in this pack split the work by format: Word documents (.docx) builds Word files and renders them to PDF only to check them, and Excel spreadsheets (.xlsx) builds workbooks with live formulas. This skill's table export writes plain values; when the spreadsheet is the deliverable, use the xlsx skill.

Install

Run one command — it saves SKILL.md and the files it uses into your agent's skills folder. Claude Code and Codex pick up a new skill without a restart; if it does not show up, restart the agent.

Claude Code — macOS, Linux
curl -fsSL --create-dirs -o ~/.claude/skills/pdf/SKILL.md https://anymodel.org/en/skills/anthropic/pdf/SKILL.md -o ~/.claude/skills/pdf/FORMS.md https://anymodel.org/en/skills/anthropic/pdf/FORMS.md -o ~/.claude/skills/pdf/LICENSE.txt https://anymodel.org/en/skills/anthropic/pdf/LICENSE.txt -o ~/.claude/skills/pdf/REFERENCE.md https://anymodel.org/en/skills/anthropic/pdf/REFERENCE.md -o ~/.claude/skills/pdf/scripts/check_bounding_boxes.py https://anymodel.org/en/skills/anthropic/pdf/scripts/check_bounding_boxes.py -o ~/.claude/skills/pdf/scripts/check_fillable_fields.py https://anymodel.org/en/skills/anthropic/pdf/scripts/check_fillable_fields.py -o ~/.claude/skills/pdf/scripts/convert_pdf_to_images.py https://anymodel.org/en/skills/anthropic/pdf/scripts/convert_pdf_to_images.py -o ~/.claude/skills/pdf/scripts/create_validation_image.py https://anymodel.org/en/skills/anthropic/pdf/scripts/create_validation_image.py -o ~/.claude/skills/pdf/scripts/extract_form_field_info.py https://anymodel.org/en/skills/anthropic/pdf/scripts/extract_form_field_info.py -o ~/.claude/skills/pdf/scripts/extract_form_structure.py https://anymodel.org/en/skills/anthropic/pdf/scripts/extract_form_structure.py -o ~/.claude/skills/pdf/scripts/fill_fillable_fields.py https://anymodel.org/en/skills/anthropic/pdf/scripts/fill_fillable_fields.py -o ~/.claude/skills/pdf/scripts/fill_pdf_form_with_annotations.py https://anymodel.org/en/skills/anthropic/pdf/scripts/fill_pdf_form_with_annotations.py && chmod +x ~/.claude/skills/pdf/scripts/extract_form_structure.py
Codex, Cursor — macOS, Linux
curl -fsSL --create-dirs -o ~/.agents/skills/pdf/SKILL.md https://anymodel.org/en/skills/anthropic/pdf/SKILL.md -o ~/.agents/skills/pdf/FORMS.md https://anymodel.org/en/skills/anthropic/pdf/FORMS.md -o ~/.agents/skills/pdf/LICENSE.txt https://anymodel.org/en/skills/anthropic/pdf/LICENSE.txt -o ~/.agents/skills/pdf/REFERENCE.md https://anymodel.org/en/skills/anthropic/pdf/REFERENCE.md -o ~/.agents/skills/pdf/scripts/check_bounding_boxes.py https://anymodel.org/en/skills/anthropic/pdf/scripts/check_bounding_boxes.py -o ~/.agents/skills/pdf/scripts/check_fillable_fields.py https://anymodel.org/en/skills/anthropic/pdf/scripts/check_fillable_fields.py -o ~/.agents/skills/pdf/scripts/convert_pdf_to_images.py https://anymodel.org/en/skills/anthropic/pdf/scripts/convert_pdf_to_images.py -o ~/.agents/skills/pdf/scripts/create_validation_image.py https://anymodel.org/en/skills/anthropic/pdf/scripts/create_validation_image.py -o ~/.agents/skills/pdf/scripts/extract_form_field_info.py https://anymodel.org/en/skills/anthropic/pdf/scripts/extract_form_field_info.py -o ~/.agents/skills/pdf/scripts/extract_form_structure.py https://anymodel.org/en/skills/anthropic/pdf/scripts/extract_form_structure.py -o ~/.agents/skills/pdf/scripts/fill_fillable_fields.py https://anymodel.org/en/skills/anthropic/pdf/scripts/fill_fillable_fields.py -o ~/.agents/skills/pdf/scripts/fill_pdf_form_with_annotations.py https://anymodel.org/en/skills/anthropic/pdf/scripts/fill_pdf_form_with_annotations.py && chmod +x ~/.agents/skills/pdf/scripts/extract_form_structure.py
Claude Code — Windows PowerShell
foreach ($f in 'SKILL.md','FORMS.md','LICENSE.txt','REFERENCE.md','scripts/check_bounding_boxes.py','scripts/check_fillable_fields.py','scripts/convert_pdf_to_images.py','scripts/create_validation_image.py','scripts/extract_form_field_info.py','scripts/extract_form_structure.py','scripts/fill_fillable_fields.py','scripts/fill_pdf_form_with_annotations.py') { $p = Join-Path "$HOME\.claude\skills\pdf" $f; New-Item -ItemType Directory -Force (Split-Path $p) | Out-Null; Invoke-WebRequest "https://anymodel.org/en/skills/anthropic/pdf/$f" -UseBasicParsing -OutFile $p }
Codex, Cursor — Windows PowerShell
foreach ($f in 'SKILL.md','FORMS.md','LICENSE.txt','REFERENCE.md','scripts/check_bounding_boxes.py','scripts/check_fillable_fields.py','scripts/convert_pdf_to_images.py','scripts/create_validation_image.py','scripts/extract_form_field_info.py','scripts/extract_form_structure.py','scripts/fill_fillable_fields.py','scripts/fill_pdf_form_with_annotations.py') { $p = Join-Path "$HOME\.agents\skills\pdf" $f; New-Item -ItemType Directory -Force (Split-Path $p) | Out-Null; Invoke-WebRequest "https://anymodel.org/en/skills/anthropic/pdf/$f" -UseBasicParsing -OutFile $p }

Any other agent: save the file into its skills folder, or give it the link to the file: https://anymodel.org/en/skills/anthropic/pdf/SKILL.md

SKILL.md

Raw

PDF Processing Guide

Overview

This guide covers essential PDF processing operations using Python libraries and command-line tools. For advanced features, JavaScript libraries, and detailed examples, see REFERENCE.md. If you need to fill out a PDF form, read FORMS.md and follow its instructions.

Quick Start

from pypdf import PdfReader, PdfWriter

# Read a PDF
reader = PdfReader("document.pdf")
print(f"Pages: {len(reader.pages)}")

# Extract text
text = ""
for page in reader.pages:
    text += page.extract_text()

Python Libraries

pypdf - Basic Operations

Merge PDFs
from pypdf import PdfWriter, PdfReader

writer = PdfWriter()
for pdf_file in ["doc1.pdf", "doc2.pdf", "doc3.pdf"]:
    reader = PdfReader(pdf_file)
    for page in reader.pages:
        writer.add_page(page)

with open("merged.pdf", "wb") as output:
    writer.write(output)
Split PDF
reader = PdfReader("input.pdf")
for i, page in enumerate(reader.pages):
    writer = PdfWriter()
    writer.add_page(page)
    with open(f"page_{i+1}.pdf", "wb") as output:
        writer.write(output)
Extract Metadata
reader = PdfReader("document.pdf")
meta = reader.metadata
print(f"Title: {meta.title}")
print(f"Author: {meta.author}")
print(f"Subject: {meta.subject}")
print(f"Creator: {meta.creator}")
Rotate Pages
reader = PdfReader("input.pdf")
writer = PdfWriter()

page = reader.pages[0]
page.rotate(90)  # Rotate 90 degrees clockwise
writer.add_page(page)

with open("rotated.pdf", "wb") as output:
    writer.write(output)

pdfplumber - Text and Table Extraction

Extract Text with Layout
import pdfplumber

with pdfplumber.open("document.pdf") as pdf:
    for page in pdf.pages:
        text = page.extract_text()
        print(text)
Extract Tables
with pdfplumber.open("document.pdf") as pdf:
    for i, page in enumerate(pdf.pages):
        tables = page.extract_tables()
        for j, table in enumerate(tables):
            print(f"Table {j+1} on page {i+1}:")
            for row in table:
                print(row)
Advanced Table Extraction
import pandas as pd

with pdfplumber.open("document.pdf") as pdf:
    all_tables = []
    for page in pdf.pages:
        tables = page.extract_tables()
        for table in tables:
            if table:  # Check if table is not empty
                df = pd.DataFrame(table[1:], columns=table[0])
                all_tables.append(df)

# Combine all tables
if all_tables:
    combined_df = pd.concat(all_tables, ignore_index=True)
    combined_df.to_excel("extracted_tables.xlsx", index=False)

reportlab - Create PDFs

Basic PDF Creation
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

c = canvas.Canvas("hello.pdf", pagesize=letter)
width, height = letter

# Add text
c.drawString(100, height - 100, "Hello World!")
c.drawString(100, height - 120, "This is a PDF created with reportlab")

# Add a line
c.line(100, height - 140, 400, height - 140)

# Save
c.save()
Create PDF with Multiple Pages
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak
from reportlab.lib.styles import getSampleStyleSheet

doc = SimpleDocTemplate("report.pdf", pagesize=letter)
styles = getSampleStyleSheet()
story = []

# Add content
title = Paragraph("Report Title", styles['Title'])
story.append(title)
story.append(Spacer(1, 12))

body = Paragraph("This is the body of the report. " * 20, styles['Normal'])
story.append(body)
story.append(PageBreak())

# Page 2
story.append(Paragraph("Page 2", styles['Heading1']))
story.append(Paragraph("Content for page 2", styles['Normal']))

# Build PDF
doc.build(story)
Subscripts and Superscripts

IMPORTANT: Never use Unicode subscript/superscript characters (₀₁₂₃₄₅₆₇₈₉, ⁰¹²³⁴⁵⁶⁷⁸⁹) in ReportLab PDFs. The built-in fonts do not include these glyphs, causing them to render as solid black boxes.

Instead, use ReportLab's XML markup tags in Paragraph objects:

from reportlab.platypus import Paragraph
from reportlab.lib.styles import getSampleStyleSheet

styles = getSampleStyleSheet()

# Subscripts: use <sub> tag
chemical = Paragraph("H<sub>2</sub>O", styles['Normal'])

# Superscripts: use <super> tag
squared = Paragraph("x<super>2</super> + y<super>2</super>", styles['Normal'])

For canvas-drawn text (not Paragraph objects), manually adjust font the size and position rather than using Unicode subscripts/superscripts.

Command-Line Tools

pdftotext (poppler-utils)

# Extract text
pdftotext input.pdf output.txt

# Extract text preserving layout
pdftotext -layout input.pdf output.txt

# Extract specific pages
pdftotext -f 1 -l 5 input.pdf output.txt  # Pages 1-5

qpdf

# Merge PDFs
qpdf --empty --pages file1.pdf file2.pdf -- merged.pdf

# Split pages
qpdf input.pdf --pages . 1-5 -- pages1-5.pdf
qpdf input.pdf --pages . 6-10 -- pages6-10.pdf

# Rotate pages
qpdf input.pdf output.pdf --rotate=+90:1  # Rotate page 1 by 90 degrees

# Remove password
qpdf --password=mypassword --decrypt encrypted.pdf decrypted.pdf

pdftk (if available)

# Merge
pdftk file1.pdf file2.pdf cat output merged.pdf

# Split
pdftk input.pdf burst

# Rotate
pdftk input.pdf rotate 1east output rotated.pdf

Common Tasks

Extract Text from Scanned PDFs

# Requires: pip install pytesseract pdf2image
import pytesseract
from pdf2image import convert_from_path

# Convert PDF to images
images = convert_from_path('scanned.pdf')

# OCR each page
text = ""
for i, image in enumerate(images):
    text += f"Page {i+1}:\n"
    text += pytesseract.image_to_string(image)
    text += "\n\n"

print(text)

Add Watermark

from pypdf import PdfReader, PdfWriter

# Create watermark (or load existing)
watermark = PdfReader("watermark.pdf").pages[0]

# Apply to all pages
reader = PdfReader("document.pdf")
writer = PdfWriter()

for page in reader.pages:
    page.merge_page(watermark)
    writer.add_page(page)

with open("watermarked.pdf", "wb") as output:
    writer.write(output)

Extract Images

# Using pdfimages (poppler-utils)
pdfimages -j input.pdf output_prefix

# This extracts all images as output_prefix-000.jpg, output_prefix-001.jpg, etc.

Password Protection

from pypdf import PdfReader, PdfWriter

reader = PdfReader("input.pdf")
writer = PdfWriter()

for page in reader.pages:
    writer.add_page(page)

# Add password
writer.encrypt("userpassword", "ownerpassword")

with open("encrypted.pdf", "wb") as output:
    writer.write(output)

Quick Reference

Task Best Tool Command/Code
Merge PDFs pypdf writer.add_page(page)
Split PDFs pypdf One page per file
Extract text pdfplumber page.extract_text()
Extract tables pdfplumber page.extract_tables()
Create PDFs reportlab Canvas or Platypus
Command line merge qpdf qpdf --empty --pages ...
OCR scanned PDFs pytesseract Convert to image first
Fill PDF forms pdf-lib or pypdf (see FORMS.md) See FORMS.md

Next Steps

  • For advanced pypdfium2 usage, see REFERENCE.md
  • For JavaScript libraries (pdf-lib), see REFERENCE.md
  • If you need to fill out a PDF form, follow the instructions in FORMS.md
  • For troubleshooting guides, see REFERENCE.md

Connect through AnyModel API

This skill runs on whatever model your agent uses. Point Claude Code, Codex or Cursor at AnyModel to run it on Claude, GPT, Gemini and more with one key — pay per token, no subscription.

More from the pack Anthropic skills

MCP server builder

Guides the agent through building an MCP server for an external API in TypeScript or Python: tool design, schemas, pagination, errors, testing and an evaluation run with Claude. Use when wrapping an API or service as MCP tools.

Skill creator with evals

Drafts or revises an agent skill, tests it with subagents against a baseline, shows results and benchmarks on a review page and tunes the description for triggering. Use when a new or edited skill has to be measured, not just written.

Distinctive frontend design

Gives new UI a visual direction drawn from its subject: a short plan of colours, type and layout, checked against the brief and against common AI-generated looks before any code. Use when a page or product screen should not look templated.

Web app testing with Playwright scripts

Tests a local web app with Python Playwright scripts: a helper starts and stops the servers, the agent inspects the rendered page, then clicks, fills, takes screenshots and reads console logs. Use when checking a frontend change or reproducing a UI bug.

Word documents (.docx)

Creates Word files with docx-js, edits existing ones as unpacked XML, adds tracked changes and comments through bundled scripts, then validates and renders the result. Use when the deliverable or input is a .docx or .dotx file.

Excel spreadsheets (.xlsx)

Builds and edits Excel workbooks with openpyxl, keeps real formulas, recalculates them in LibreOffice with a JSON error report and follows financial-model conventions. Use when the deliverable is a spreadsheet file such as .xlsx, .xlsm or .csv.

PowerPoint decks (.pptx)

Creates themed decks with pptxgenjs, edits templates as unpacked XML with scripts for slide text, thumbnails, duplication and validation, and checks every slide as an image. Use when a task creates, edits or reads a .pptx or .potx file.

Claude API reference for agents

Anthropic's reference for code that calls Claude: SDKs in seven languages and cURL, current models and prices, tool use, caching, Managed Agents, plus migration, cost and eval procedures. Use when writing or changing code that uses the Claude API.

Algorithmic art with p5.js

Creates generative art in p5.js: a short manifesto for the piece, then a seeded algorithm in one HTML page with sliders, seed navigation and PNG download. Use when asked for flow fields, particle systems or other art made with code.

Document co-authoring workflow

Guides the user through writing a document in three stages: context gathering with numbered questions, section-by-section drafting with brainstormed options, and a test on a subagent that sees only the text. Use when drafting a spec, proposal or decision doc.