pdf-merge-split
Combine multiple PDFs into one or split a PDF into separate files. Use when a user asks to merge PDFs, combine PDF files, join documents together, split a PDF into pages, extract pages from a PDF, or separate a PDF into parts. Supports page range selection and custom ordering.
What this skill does
# PDF Merge & Split
## Overview
Combine multiple PDF files into a single document or split a PDF into separate files by page ranges. This skill handles merging in a specified order, splitting by page numbers, extracting specific pages, and preserving bookmarks and metadata where possible.
## Instructions
When a user asks to merge or split PDF files, follow these steps:
### Step 1: Determine the operation
Ask or infer what the user needs:
- **Merge**: Combine multiple PDFs into one output file
- **Split by pages**: Break a single PDF into multiple files by page ranges
- **Extract pages**: Pull specific pages out into a new PDF
- **Split by size**: Divide a PDF into chunks of N pages each
### Step 2: Validate the input files
Check that all input files exist and are valid PDFs:
```python
import os
from PyPDF2 import PdfReader
def validate_pdfs(file_paths):
results = []
for path in file_paths:
if not os.path.exists(path):
results.append({"file": path, "status": "not found"})
continue
try:
reader = PdfReader(path)
results.append({
"file": path,
"status": "valid",
"pages": len(reader.pages)
})
except Exception as e:
results.append({"file": path, "status": f"invalid: {e}"})
return results
```
### Step 3: Perform the operation
**For merging:**
```python
from PyPDF2 import PdfMerger
def merge_pdfs(input_paths, output_path):
merger = PdfMerger()
for path in input_paths:
merger.append(path)
merger.write(output_path)
merger.close()
return output_path
```
**For splitting by page ranges:**
```python
from PyPDF2 import PdfReader, PdfWriter
def split_pdf(input_path, ranges, output_dir="."):
reader = PdfReader(input_path)
output_files = []
for i, (start, end) in enumerate(ranges):
writer = PdfWriter()
for page_num in range(start - 1, min(end, len(reader.pages))):
writer.add_page(reader.pages[page_num])
output_path = os.path.join(output_dir, f"split_{i+1}_pages_{start}-{end}.pdf")
with open(output_path, "wb") as f:
writer.write(f)
output_files.append(output_path)
return output_files
```
**For extracting specific pages:**
```python
def extract_pages(input_path, page_numbers, output_path):
reader = PdfReader(input_path)
writer = PdfWriter()
for page_num in page_numbers:
if 1 <= page_num <= len(reader.pages):
writer.add_page(reader.pages[page_num - 1])
with open(output_path, "wb") as f:
writer.write(f)
return output_path
```
### Step 4: Verify and report results
After the operation, verify the output:
1. Confirm the output file exists and is a valid PDF
2. Report the page count of each output file
3. Show file sizes for the user
## Examples
### Example 1: Merge three reports into one
**User request:** "Combine report-q1.pdf, report-q2.pdf, and report-q3.pdf into annual-report.pdf"
**Actions taken:**
1. Validate all three input files
2. Merge in the specified order
3. Write to annual-report.pdf
**Output:**
```
Merged 3 PDF files into annual-report.pdf
Input files:
1. report-q1.pdf (12 pages)
2. report-q2.pdf (15 pages)
3. report-q3.pdf (11 pages)
Output: annual-report.pdf (38 pages, 2.4 MB)
```
### Example 2: Split a PDF into chapters
**User request:** "Split textbook.pdf into separate files: pages 1-30, 31-55, 56-80"
**Actions taken:**
1. Validate textbook.pdf (80 pages)
2. Split into three page ranges
3. Save each range as a separate file
**Output:**
```
Split textbook.pdf into 3 files:
1. split_1_pages_1-30.pdf (30 pages, 1.1 MB)
2. split_2_pages_31-55.pdf (25 pages, 0.9 MB)
3. split_3_pages_56-80.pdf (25 pages, 0.8 MB)
All files saved to current directory.
```
### Example 3: Extract specific pages
**User request:** "Pull out pages 5, 12, and 18-22 from presentation.pdf"
**Actions taken:**
1. Parse the page specification: [5, 12, 18, 19, 20, 21, 22]
2. Extract those pages from presentation.pdf
3. Save as extracted_pages.pdf
**Output:**
```
Extracted 7 pages from presentation.pdf
Pages extracted: 5, 12, 18, 19, 20, 21, 22
Output: extracted_pages.pdf (7 pages, 540 KB)
```
## Guidelines
- Always validate input files before processing. Report clear errors for missing or corrupt files.
- Preserve the original files. Never modify input PDFs in place.
- When merging, respect the order specified by the user. If no order is given, use alphabetical.
- Use 1-based page numbering in all user-facing output to match what users see in PDF viewers.
- For encrypted PDFs, inform the user that a password is needed before processing.
- When splitting, create descriptive filenames that include page ranges.
- Report file sizes alongside page counts so the user knows the output scale.
- Install PyPDF2 with `pip install PyPDF2` if not available. For advanced features like preserving form fields, use pikepdf instead.
Related in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.