agentleFS
nb-99nb-99/skillektion/skills/pdf/SKILL.md

pdf

Skill1 starsChanged 3 months agoMITView on GitHub

Work with PDF files. Use when the user mentions a PDF and wants to extract text or tables, fill form fields, merge, split, rotate, encrypt, or decrypt pages, stamp a watermark, generate a PDF, or OCR a scan — phrases like "extract the text from this PDF", "fill out this form", "merge these PDFs", "add a watermark". Not for converting documents between office formats (docx, xlsx have their own skills) or for rendering PDFs in a browser.

  • Installs packages

197 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use context7-efficient, file-reading and 9 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • hfzarslanSkill

    context7-efficient

    Token-efficient library documentation fetcher using Context7 MCP with 86.8% token savings through intelligent shell pipeline filtering. Fetches code examples, API references, and best practices for JavaScript, Python, Go, Rust, and other libraries. Use when users ask about library documentation, need code examples, want API usage patterns, are learning a new framework, need syntax reference, or troubleshooting with library-specific information. Triggers include questions like "Show me React hooks", "How do I use Prisma", "What's the Next.js routing syntax", or any request for library/framework documentation.

    Also in 5 projects that use this

  • SeifBenayedSkill

    file-reading

    Use this skill when a file has been uploaded but its content is NOT in your context — only its path at /mnt/user-data/uploads/ is listed in an uploaded_files block. This skill is a router: it tells you which tool to use for each file type (pdf, docx, xlsx, csv, json, images, archives, ebooks) so you read the right amount the right way instead of blindly running cat on a binary. Triggers: any mention of /mnt/user-data/uploads/, an uploaded_files section, a file_path tag, or a user asking about an uploaded file you have not yet read. Do NOT use this skill if the file content is already visible in your context inside a documents block — you already have it.

    Also in 6 projects that use this

  • SeifBenayedSkill

    pdf-reading

    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.

    Also in 6 projects that use this

  • yf8578Skill

    market-research-reports

    Generate comprehensive market research reports (50+ pages) in the style of top consulting firms (McKinsey, BCG, Gartner). Features professional LaTeX formatting, extensive visual generation with scientific-schematics and generate-image, deep integration with research-lookup for data gathering, and multi-framework strategic analysis including Porter Five Forces, PESTLE, SWOT, TAM/SAM/SOM, and BCG Matrix.

    Also in 7 projects that use this

  • OpenAISkill

    migrate-to-codex

    Migrate supported instruction files, skills, agents, and MCP config into Codex project and global files.

    Also in 4 projects that use this

  • jjyaoaoSkill

    gift-evaluator

    The PRIMARY tool for Spring Festival gift analysis and social interaction generation. Use this skill when users upload photos of gifts (alcohol, tea, supplements, etc.) to inquire about their value, authenticity, or how to respond socially. Integrates visual perception, market valuation, and HTML card generation.

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 186 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read values back with PdfReader(out).get_fields() and render: pdftoppm -png -r 100 out.pdf check — confirm the PNG is non-trivial in size …

    line 42
  2. Distinctive:

    Create a stamp page (one page, same size as the target) with reportlab, then overlay it:

    line 63
  3. Distinctive:

    Never ship a PDF you haven't opened.

    line 95
  4. Distinctive:

    Check availability first, then install what's missing:

    line 106
  5. Distinctive:

    Never assume anything is preinstalled — verify with the checks above and report what you installed.

    line 116

“Common” is measured: kept by at least 6 in 10 of the 186 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Working with PDFs

Pick the library by job, not by preference:

TaskTool
Read text preserving layoutpdftotext -layout (poppler CLI)
Programmatic text + tables, per-character geometrypdfplumber
Page surgery: merge, split, rotate, stamp, encryptpypdf (bundled scripts/pdf_ops.py)
Inspect / fill AcroForm fieldsbundled scripts/inspect_form.py / fill_form.py
Generate PDFsreportlab (canvas for pixel control, platypus for flowing documents)
Rasterize for visual checkspdftoppm (poppler), or pdf2image + pytesseract for OCR

Read and extract

  • pdftotext -layout in.pdf out.txt keeps column alignment; plain pdftotext reflows and is better for prose. Both are poppler CLI tools.
  • pdfplumber when you need positions or tables. page.extract_text(layout=True) approximates the CLI layout mode; page.extract_tables() finds ruled tables. For tables without ruling lines pass page.extract_tables({"vertical_strategy": "text", "horizontal_strategy": "text"}) — the default lines strategy returns [] when the PDF has no drawn cell borders. extract_table returns list-of-lists; wrap in pandas.DataFrame(...) yourself (pandas is optional).
  • Rotated or diagonal text (stamps, landscape pages) extracts per-character or out of order. When checking for a watermark, strip whitespace from pdftotext output before searching, or read back with pypdf per page.

Page operations

The bundled scripts/pdf_ops.py wraps the pypdf calls (merge, split, rotate, encrypt, decrypt, watermark stamp, info as JSON). Use it first; drop to pypdf directly for anything finer.

pypdf gotchas:

  • PdfReader.is_encrypted then reader.decrypt(password) before any page access; decrypt returns a truthy password type — check it, a wrong password yields PasswordType.NOT_DECRYPTED.
  • writer.encrypt(user_password=..., owner_password=...) defaults to RC4-128. Pass algorithm="AES-256" for modern encryption (writes /V 5).
  • page.rotate(90) accumulates into /Rotate; multiples of 90 only.
  • writer.append(reader) copies pages plus outline/named destinations; add_page copies bare pages.

Forms (AcroForm)

Workflow: inspect → fill → verify by reading values back AND by rendering pages to images.

  1. scripts/inspect_form.py form.pdf — JSON of every field: fully-qualified name, type (text/checkbox/radio/combobox/listbox/signature), current value, options (choice entries or button on-states), rectangle, required, read-only. Parent/child hierarchies are flattened; radio groups collapse to one record with their on-states listed as options.
  2. scripts/fill_form.py form.pdf "full_name=Ada Lovelace" priority=High -o out.pdf (or --json values.json; checkboxes accept true/false). It reports a JSON summary of set vs missing fields and exits 1 when a requested field is missing. Signature fields are never filled.
  3. Read values back with PdfReader(out).get_fields() and render: pdftoppm -png -r 100 out.pdf check — confirm the PNG is non-trivial in size and dimensions match pdfinfo.

Key behavior of update_page_form_field_values (verified against pypdf 6.x):

  • It regenerates appearance streams for text (/Tx) and choice (/Ch) fields on every update, so filled values are visible in any viewer.
  • Pass auto_regenerate=False to clear /NeedAppearances on the AcroForm. The default True sets the flag and asks the viewer to regenerate appearances — some viewers ignore that and show blank fields, so always clear it.
  • There is no PdfWriter.flatten() method. Flattening means update_page_form_field_values(..., flatten=True): the appearance is stamped into the page content stream, but the widget annotations remain. If a job truly needs annotation-free output, rebuild the page with a rasterized or re-drawn copy.
  • Checkbox values must be the on-state name from /AP /N (usually /Yes or /On, reportlab uses /Yes) or /Off; a value that matches no on-state silently falls back to /Off.

Create with reportlab

  • Canvas (reportlab.pdfgen.canvas) for absolute control: drawString, rect, line, and canvas.acroForm.textfield(...) / .choice(...) / .checkbox(...) / .radio(...) for form widgets.
  • Platypus (SimpleDocTemplate + flowables) for flowing documents with wrapped paragraphs, tables, and page breaks.
  • Colors passed to acroForm widgets must be Color instances (reportlab.lib.colors.black, Color(0.95,0.95,0.95)); bare floats that worked in old reportlab now raise AttributeError.
  • Draw at least one string on the canvas before adding form widgets; a page with widgets but no content can fail with a "forward reference to 'Page1'" error at save time.
  • Base-14 fonts (Helvetica, Times, Courier) are single-byte encoded. Characters outside Latin-1/WinAnsi come out as wrong glyphs — H₂SO₄ renders as HnSOn (a black box is the other common symptom). Superscript digits ²³¹ survive because they are Latin-1. For sub/superscripts use Paragraph markup H<sub>2</sub>SO<sub>4</sub>, x<super>2</super>, or draw the smaller font at a manual offset; never rely on Unicode sub/superscript codepoints with base-14 fonts.
  • Non-Latin text (Cyrillic, Greek, CJK) needs a registered TrueType font: pdfmetrics.registerFont(TTFont("Ar", "Arial.ttf")) then setFont("Ar", 14). The TTF embeds as a subset and text extracts correctly afterward.
  • To build an editable form field for later filling: canvas.acroForm.textfield(name="full_name", x=..., y=..., width=..., height=..., ...). Note reportlab's y origin is the page bottom.

Watermarks

Create a stamp page (one page, same size as the target) with reportlab, then overlay it:

from pypdf import PdfReader, PdfWriter
stamp = PdfReader("stamp.pdf").pages[0]
writer = PdfWriter(clone_from="base.pdf")
for page in writer.pages:
    page.merge_page(stamp)
writer.write("out.pdf")

merge_page pastes at 1:1 using the stamp's own coordinates; use merge_transformed_page(stamp, Transformation().scale(...)) to scale or reposition. Set the stamp fill with alpha (setFillColorRGB(0.7,0.7,0.7, alpha=0.5)).

OCR scanned PDFs

Rasterize with pdf2image, then OCR with pytesseract:

from pdf2image import convert_from_path
import pytesseract
pages = convert_from_path("scan.pdf", dpi=300)
text = "\n".join(pytesseract.image_to_string(p) for p in pages)

Caveats:

  • pdf2image shells out to poppler's pdfinfo/pdftoppm — they must be on PATH or you get PDFInfoNotInstalledError: Unable to get page count. Pass poppler_path= if poppler lives outside PATH.
  • OCR quality tracks scan resolution: 300 dpi for body text, 400+ for small print; low-dpi scans misread digits and confusable glyphs. Check a rendered page image first — if a human can't read it, tesseract won't either.
  • pytesseract needs the tesseract binary installed separately (it is not a Python dependency). If tesseract is missing from PATH, tell the user and stop rather than silently skipping OCR.

Verify the output

Never ship a PDF you haven't opened. Loop:

  1. pdfinfo out.pdf — page count, page size, encryption status; compare against expectation.
  2. pdftotext out.pdf - (add -layout for forms/tables) — confirm the content that must be visible in plain readers is actually there.
  3. pdftoppm -png -r 100 out.pdf page — rasterize; confirm each page renders, the file is a plausible size (a blank or broken page is a few KB), and dimensions match the page size at that dpi. Read the image back to check it isn't blank when content was expected.
  4. For generated form output, re-read field values with pypdf and confirm appearance streams carry the values (a Tj with the filled text in /AP /N), or trust pdftotext showing the values.

Note pdftoppm may print a harmless Fontconfig error on minimal systems; the PNG is still written — check the file, not the exit banner.

Dependencies

Check availability first, then install what's missing:

command -v pdftotext pdfinfo pdftoppm tesseract   # poppler + OCR binaries
python3 -c "import pypdf, pdfplumber, reportlab"  # python libraries
  • Python: pip install pypdf pdfplumber reportlab pdf2image pytesseract (into a venv; all pure-Python except pdfplumber's optional PIL dependency, which pip resolves).
  • Poppler CLI (pdftotext, pdfinfo, pdftoppm, pdfimages): system package poppler-utils (Debian/Ubuntu), poppler (macOS brew, nix poppler-utils).
  • OCR: tesseract binary plus language packs (tesseract-ocr-eng on Debian); pdfimages -png in.pdf prefix extracts embedded scan images when OCR-ing a single page region is better than the full raster.
  • Never assume anything is preinstalled — verify with the checks above and report what you installed.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.