← 返回列表
全部 Skill›内容与媒体 Content & Media›pdf-reading

pdf-reading

作者 @asgeirtj · 语言 en
Use this skill when you need to read, inspect, or extract content from PDF files — especially when file content is NOT in your context and you need to read it from disk. Covers content inventory, text extraction, page rasterization for visual inspection, embedded image/attachment/table/form-field extraction, and choosing the right reading strategy for different document types (text-heavy, scanned, slide-decks, forms, data-heavy). Do NOT use this skill for PDF creation, form filling, merging, splitting, watermarking, or encryption — use the pdf skill instead.
内容与媒体 Content & Media文档处理通用执行命令读写文件待翻译
最近源活动
—
检测 SKILL.md 语言
en
星标 ★
72,578
分支 Fork
0
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

PDF Processing Guide

Overview

This guide covers essential PDF reading operations using Python libraries and command-line tools. For advanced features (pypdfium2 rendering, pdfplumber table settings, OCR fallback, encrypted/corrupted PDF handling), see REFERENCE.md.

Reading & Inspecting PDFs

Before doing anything with a PDF, understand what you're working with.

Content inventory

Run a quick diagnostic first. For simple tasks ("summarize this

document"), pdfinfo + pdffonts + a text sample may suffice. For

anything involving figures, attachments, or extraction issues, run the

full set:

# Always: page count, file size, PDF version, metadata
pdfinfo document.pdf

# Always: does a text layer exist? No fonts → scanned/raster → see "Scanned documents"
pdffonts document.pdf

# If fonts are present: sample the text layer
pdftotext -f 1 -l 1 document.pdf - | head -20

# If figures/charts may matter:
pdfimages -list document.pdf

# If the PDF might contain embedded files (reports, portfolios):
pdfdetach -list document.pdf

This tells you:

  • Page count and size — how big is the job?
  • Font status — are any fonts present? An empty pdffonts table

means the PDF is scanned or raster-only: pdftotext will return

nothing, so skip straight to "Scanned documents" below. Fonts shown

as not embedded ("emb: no") with custom encodings may produce wrong

characters on extraction.

  • Text extractability — when fonts exist, does pdftotext return

clean text, or is it garbled (broken encoding)?

  • Embedded raster images — are there photos or raster figures?

(Note: vector-drawn charts from matplotlib/Excel won't appear — see

"Extracting embedded images" below)

  • Attachments — are there embedded spreadsheets, data files, etc.?

Text extraction

pypdf for basic text:

from pypdf import PdfReader

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

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

pdftotext preserving layout (better for multi-column docs):

# Layout mode preserves spatial positioning
pdftotext -layout document.pdf output.txt

# Specific page range
pdftotext -f 1 -l 5 document.pdf output.txt

pdfplumber for layout-aware extraction with positioning data:

import pdfplumber

with pdfplumber.open("document.pdf") as pdf:
    for page in pdf.pages:
        text = page.extract_text()
        print(text)

Visual inspection (rasterize pages)

Text extraction is blind to charts, diagrams, figures, equations,

multi-column layout, and form structures. When any of these matter,

rasterize the relevant page and Read the image:

# Rasterize a single page (page 3 here) at 150 DPI
pdftoppm -jpeg -r 150 -f 3 -l 3 document.pdf /tmp/page

# pdftoppm zero-pads the output filename based on TOTAL page count
# (e.g., page-03.jpg for a 50-page PDF, page-003.jpg for 200+ pages)
# Don't guess the filename — find it:
ls /tmp/page-*.jpg

Then Read the resulting image file. This gives you full visual

understanding of that page — layout, charts, equations, everything.

When to rasterize vs. text-extract:

  • Content/data questions → text extraction (cheaper, searchable)
  • Figures, charts, visual layout → rasterize the page
  • Tables → try text extraction first, rasterize if garbled
  • Precision matters → do both (extract text AND rasterize; use text

for data, image for context — this is what Claude's API does natively

with PDF uploads)

Token cost awareness:

  • Text extraction: ~200–400 tokens per page
  • Rasterized image: ~1,600 tokens per page (at 150 DPI)
  • Both together: ~2,000–2,400 tokens per page

For a 100-page PDF, rasterizing everything would consume ~160K tokens.

Only rasterize pages that matter for the question at hand.

Choosing your reading strategy

Text-heavy documents (reports, articles, books):

→ Text extraction is primary. Rasterize only for specific figures or

pages where layout matters.

Scanned documents (pdffonts shows no fonts):

→ pdftotext will return nothing — don't run it. Rasterize pages at

150 DPI and Read them visually. For bulk text extraction, use OCR

(pytesseract after converting pages to images — see REFERENCE.md for

a complete example).

Slide-deck PDFs (exported presentations):

→ Every page is primarily visual. Rasterize individual pages on demand.

Text extraction gives you bullet-point text but loses all layout.

Form-heavy documents:

→ Extract form field values programmatically first (see below). Rasterize

the form page for visual context if needed.

Data-heavy documents (tables, charts, figures):

→ Use pdfplumber for tables. Rasterize pages with charts/figures.

Extract text for surrounding narrative. Consider both text AND image

for the same page when precision matters.

Extracting embedded images

# List all embedded images with metadata (size, color, compression)
pdfimages -list document.pdf

# Extract all images as PNG
pdfimages -png document.pdf /tmp/img

# Extract from specific pages only (pages 3-5)
pdfimages -png -f 3 -l 5 document.pdf /tmp/img

# Extract in original format (JPEG stays JPEG, etc.)
pdfimages -all document.pdf /tmp/img

Then Re

评论
Aasgeirtj
asgeirtj
asgeirtj/system_prompts_leaks
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@asgeirtj
所属大类内容与媒体 Content & Media / 文档处理
国内可用性通用
最近源活动—
风险提示执行命令、读写文件
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。