CherryHQ/cherry-studio / resources/skills/office-transform
office-transform
VerifiedExtract or edit a selection from xlsx, docx, pdf, or pptx into a new file; the source is never modified.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 18.0 KB |
| references/docx-edit.md | markdown | 3.7 KB |
| references/pptx-edit.md | markdown | 4.6 KB |
| scripts/office/__init__.py | script | 0 B |
| scripts/office/common.py | script | 7.6 KB |
| scripts/office/docx.py | script | 19.0 KB |
| scripts/office/ooxml.py | script | 7.1 KB |
| scripts/office/pdf.py | script | 1.8 KB |
| scripts/office/pptx.py | script | 4.4 KB |
| scripts/office/xlsx.py | script | 28.3 KB |
| scripts/office_extract.py | script | 2.6 KB |
| scripts/office_patch_copy.py | script | 4.9 KB |
scripts/office/pdf.py
View on GitHub"""Everything pdf: the extract path. A PDF is not an OOXML package, so this module reaches
common.py for its size ceiling and never touches ooxml.py.
pypdf is imported inside extract_pdf, never at module scope: office_extract.py imports this
module eagerly for every format, and a top-level third-party import would make a pypdf-less
environment fail on an xlsx source.
"""
from pathlib import Path
from office.common import MAX_ENTRY_BYTES, fail, require_index, slice_char_range
def extract_pdf(src: Path, anchor: dict, out_path: Path, out_format: str) -> None:
try:
from pypdf import PdfReader, PdfWriter
except ImportError:
fail("pypdf is required for pdf sources — rerun via `uv run --with pypdf python ...`")
if anchor.get("page") is None:
fail("pdf anchor requires a one-based 'page' number")
page_number = require_index(anchor.get("page"), "pdf anchor 'page'", 1)
page_index = page_number - 1
# OOXML sources go through preflight_zip; PDFs had no ceiling at all before PdfReader parsed them.
source_bytes = src.stat().st_size
if source_bytes > MAX_ENTRY_BYTES:
fail(f"pdf is {source_bytes} bytes (limit {MAX_ENTRY_BYTES}); ask for a smaller file")
reader = PdfReader(str(src))
if page_index >= len(reader.pages):
fail(f"page {page_number} out of range (document has {len(reader.pages)} pages)")
page = reader.pages[page_index]
if out_format == "pdf":
writer = PdfWriter()
writer.add_page(page)
with out_path.open("wb") as handle:
writer.write(handle)
elif out_format in ("txt", "md"):
text = slice_char_range(page.extract_text() or "", anchor.get("charRange"))
out_path.write_text(text + "\n", encoding="utf-8")
else:
fail(f"unsupported output format for pdf source: {out_format!r} (use pdf, txt, or md)")
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations. | Stars: 195k | Updated | Claude CodeCodex | Verified | Install |
| docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation. | Stars: 195k | Updated | Claude CodeCodex | Verified | Install |
| pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill. | Stars: 195k | Updated | Claude CodeCodex | Verified | Install |
| pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill. | Stars: 195k | Updated | Claude CodeCodex | Verified | Install |