Pdf edit
Skill mdonmez/skills/pdf-edit
A curated list of skills designed to enhance AI Agents' capabilities across a range of instructions.
npx -y skills add mdonmez/skills --skill pdf-editAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Process, manipulate, and edit PDF files using PyMuPDF (fitz). Merge, split, rotate, encrypt/decrypt, extract text/images, add watermarks, compress, and inspect PDFs. Use this skill when the user asks to combine PDFs, split pages, extract content, add passwords, rotate pages, convert PDF pages to images, or perform any PDF editing or transformation task. Triggers on phrases like "pdf merge", "pdf split", "pdf birleştir", "pdf düzenle", "pdf şifrele", "pdf den metin çıkar", "pdf rotasyon", "pdf sıkıştır", and any PDF manipulation request.
SKILL.md
5.7 KB, ~1.6k tokens by cl100k_base, as published. Nobody here has run it
PDF Edit — General PDF Processing with PyMuPDF
Use PyMuPDF (fitz) for all PDF operations. It handles both editing and content extraction in a single library.
Prerequisites
PyMuPDF loads automatically via uv run --with pymupdf:
uv run --with pymupdf python -c "import fitz; print(fitz.version)"
Common Operations
All snippets assume import fitz and use raw strings (r"...") for Windows paths.
1. Merge PDFs
uv run --with pymupdf python -c "
import fitz
dst = fitz.open()
for path in [r'dir\file1.pdf', r'dir\file2.pdf']:
src = fitz.open(path)
dst.insert_pdf(src)
src.close()
dst.save(r'dir\output.pdf', garbage=4, deflate=True)
dst.close()
print('Merged')
"
2. Split PDF (extract specific pages)
uv run --with pymupdf python -c "
import fitz
src = fitz.open(r'dir\input.pdf')
dst = fitz.open()
dst.insert_pdf(src, from_page=0, to_page=0) # first page only
dst.save(r'dir\page1.pdf')
dst.close()
src.close()
print('Split')
"
3. Extract text
uv run --with pymupdf python -c "
import fitz
doc = fitz.open(r'dir\input.pdf')
for i, page in enumerate(doc):
text = page.get_text('text') # 'text', 'blocks', 'html', 'dict', 'json'
print(f'--- Page {i+1} ---')
print(text)
doc.close()
"
4. Extract images
uv run --with pymupdf python -c "
import fitz, os
doc = fitz.open(r'dir\input.pdf')
for i, page in enumerate(doc):
for j, img in enumerate(page.get_images()):
xref = img[0]
pix = fitz.Pixmap(doc, xref)
if pix.n - pix.alpha < 4:
pix.save(rf'dir\page{i+1}_img{j+1}.png')
else:
pix1 = fitz.Pixmap(fitz.csRGB, pix)
pix1.save(rf'dir\page{i+1}_img{j+1}.png')
print(f'Page {i+1}, image {j+1}: saved')
doc.close()
"
5. Rotate pages
uv run --with pymupdf python -c "
import fitz
doc = fitz.open(r'dir\input.pdf')
for page in doc:
page.set_rotation(90) # 0, 90, 180, 270
doc.save(r'dir\rotated.pdf', garbage=4, deflate=True)
doc.close()
print('Rotated')
"
6. Encrypt / password-protect
uv run --with pymupdf python -c "
import fitz
doc = fitz.open(r'dir\input.pdf')
doc.save(r'dir\encrypted.pdf',
encryption=fitz.PDF_ENCRYPT_AES_256,
user_pw='user123',
owner_pw='owner456')
doc.close()
print('Encrypted')
"
7. Decrypt / open encrypted PDF
uv run --with pymupdf python -c "
import fitz
doc = fitz.open(r'dir\encrypted.pdf')
if doc.is_encrypted:
doc.authenticate('user123')
print('Pages:', doc.page_count)
doc.close()
"
8. Page to image (PNG/JPEG)
uv run --with pymupdf python -c "
import fitz
doc = fitz.open(r'dir\input.pdf')
page = doc[0]
pix = page.get_pixmap(dpi=150) # default 72
pix.save(r'dir\page1.png')
doc.close()
print('Saved as image')
"
9. Compress / optimize
uv run --with pymupdf python -c "
import fitz
doc = fitz.open(r'dir\input.pdf')
doc.save(r'dir\optimized.pdf',
garbage=4, # remove unused objects
deflate=True, # compress streams
clean=True) # clean up structure
doc.close()
print('Optimized')
"
10. Add text annotation / watermark
uv run --with pymupdf python -c "
import fitz
doc = fitz.open(r'dir\input.pdf')
for page in doc:
r = page.rect
page.insert_text(
(r.width/2 - 50, r.height/2),
'WATERMARK',
fontsize=48,
color=(0.5, 0.5, 0.5),
overlay=False)
doc.save(r'dir\watermarked.pdf')
doc.close()
print('Watermarked')
"
11. Inspect / get metadata
uv run --with pymupdf python -c "
import fitz
doc = fitz.open(r'dir\input.pdf')
print('Pages:', doc.page_count)
print('Metadata:', doc.metadata)
print('Table of Contents:', doc.get_toc())
for page in doc:
print(f'Page {page.number + 1}: {page.rect.width:.0f}x{page.rect.height:.0f}')
doc.close()
"
12. Delete / reorder pages
uv run --with pymupdf python -c "
import fitz
doc = fitz.open(r'dir\input.pdf')
# Delete page 2 (0-indexed)
doc.delete_page(1)
# Move page 1 to after page 3
doc.move_page(0, 2)
doc.save(r'dir\reordered.pdf')
doc.close()
print('Reordered')
"
Gotchas
- Windows paths: Always use raw strings (
r"C:\path\file.pdf") or escape backslashes ("C:\\path\\file.pdf") - Turkish/special characters in filenames: handled correctly with raw strings
- Encrypted files: Check
doc.is_encryptedbefore reading; calldoc.authenticate(password)to unlock - Resource cleanup: Always call
doc.close()to release file handles, especially in loops - Merge vs insert_pdf:
insert_pdfcopies pages from another PDF document object; first open each source withfitz.open() - Performance: For large PDFs (>100 pages), use
save(garbage=4, deflate=True)to keep file size manageable - pypdf alternative: If PyMuPDF is not suitable (rare edge cases), fall back to
uv run --with pypdf python ...with the same pattern —pypdf.PdfWriterfor merging,pypdf.PdfReaderfor reading - pymupdf not installed: Automatically resolved via
uv run --with pymupdf; no manual pip install needed
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 0 of the 12 instructions most pdf office docs skills give in ~1.6k tokens
Counted across 636 of the 690 authors here whose files we hold, read 2026-08-07
- extract text using pdfplumberin 89 of 636, across 23 files
- create PDFs using reportlabin 83 of 636, across 16 files
- read forms.md to fill out pdf formsin 80 of 636, across 13 files
- OCR scanned PDFs using pytesseractin 77 of 636, across 10 files
- merge or split PDFs using qpdfin 70 of 636, across 3 files
- use excel formulas instead of hardcoded calculated valuesin 68 of 636, across 13 files
- unpack edit xml and repack existing documentsin 63 of 636, across 8 files
- document sources for hardcoded valuesin 61 of 636, across 9 files
- write minimal python code without unnecessary commentsin 59 of 636, across 7 files
- run the recalculation script after adding or modifying formulasin 59 of 636, across 7 files
- fix all identified formula errors and recalculatein 58 of 636, across 6 files
- format years as text stringsin 57 of 636, across 5 files
Said here and by no other author read
- run via uv run with pymupdf
- use raw strings for file paths
- check is_encrypted before reading encrypted files
- call doc.close to release file handles
- open sources with fitz.open before inserting
- use garbage and deflate for large PDFs
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.