Skip to content

aipoch/open-science / resources/skills/pdf-generation

pdf-generation

Verified

Use when creating a PDF report, handout, or poster with Python, or when merging, splitting, rotating, watermarking, encrypting, filling forms in, or extracting tables from an existing PDF inside the Notebook. Covers ReportLab layout with embedded Unicode/CJK fonts, pypdf and pdfplumber processing, page rendering for visual QA, and Artifact delivery. For reading or citing a library paper, prefer read_document, list_pdf_elements, and read_library_pdf.

FileKindSize
README.mdmarkdown2.0 KB
SKILL.mdskill md12.0 KB
kernel.pyscript13.7 KB
open-science.jsonconfig367 B
references/forms.mdmarkdown4.6 KB
references/processing.mdmarkdown6.4 KB
# PDF generation and processing skill

On-demand skill for creating PDFs with ReportLab and processing existing PDFs
with pypdf, pdfplumber, and pypdfium2 inside the Open Science Notebook.

## Execution boundary

The Notebook and shell cannot necessarily read this skill directory. Code that
the model needs at run time is in `kernel.py`, registered in `open-science.json`
and injected with `kernelSkillIds: ["pdf-generation"]`. The helpers import their
third-party packages lazily, so injection succeeds before the packages are
installed; a call reports the missing module through the normal recovery flow,
and the model installs packages with `manage_packages`. No command-line PDF tool,
Office engine, or font is bundled.

## Helpers

- `register_pdf_fonts`: registers an embeddable TrueType family. CJK lookup covers
  macOS (STHeiti, Songti, Arial Unicode), Windows (Microsoft YaHei, SimHei,
  SimSun), and common Linux packages (WenQuanYi, Droid Sans Fallback). CFF-based
  fonts such as Hiragino and most `.otf` files are skipped because ReportLab cannot
  embed them. The non-CJK default is matplotlib's DejaVu Sans.
- `render_pdf_pages`: pypdfium2 rendering sized for `host.viewImage` (1568 px).
- `inspect_pdf`: text-layer, font-embedding, outline, and form summary.
- `pdf_form_fields`, `fill_pdf_form`: AcroForm listing and validated filling.

## Attribution

The workflow and form-filling procedure are adapted from the `pdf` skill in
[anthropics/skills](https://github.com/anthropics/skills) (Apache-2.0). Changes:
Open Science execution and Artifact delivery, removal of CLI tools that are not
bundled, embedded-font handling, helper functions in place of scripts.

## Validation

```sh
python3 -m unittest discover -s test/pdf-generation -v
npx vitest run src/main/skills/pdf-generation.test.ts
```

The Python suite skips when ReportLab, pypdf, pdfplumber, or pypdfium2 are not
installed in the test interpreter; set `OPEN_SCIENCE_TEST_PYTHON` to an
interpreter that has them for a full run.
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall