pypdf-3-page-rotation-and-transformation
Sub-skill of pypdf: 3. Page Rotation and Transformation.
Best use case
pypdf-3-page-rotation-and-transformation is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Sub-skill of pypdf: 3. Page Rotation and Transformation.
Teams using pypdf-3-page-rotation-and-transformation should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/3-page-rotation-and-transformation/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How pypdf-3-page-rotation-and-transformation Compares
| Feature / Agent | pypdf-3-page-rotation-and-transformation | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Sub-skill of pypdf: 3. Page Rotation and Transformation.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 3. Page Rotation and Transformation
## 3. Page Rotation and Transformation
```python
"""
Rotate, crop, and transform PDF pages.
"""
from pypdf import PdfReader, PdfWriter, Transformation
from pypdf.generic import RectangleObject
from pathlib import Path
from typing import List, Optional
def rotate_pages(
input_path: str,
output_path: str,
rotation: int,
pages: Optional[List[int]] = None
) -> None:
"""Rotate PDF pages by specified degrees.
Args:
input_path: Source PDF file
output_path: Destination file
rotation: Rotation in degrees (90, 180, or 270)
pages: List of page numbers to rotate (0-indexed), None for all
"""
if rotation not in [90, 180, 270]:
raise ValueError("Rotation must be 90, 180, or 270 degrees")
reader = PdfReader(input_path)
writer = PdfWriter()
for i, page in enumerate(reader.pages):
if pages is None or i in pages:
page.rotate(rotation)
writer.add_page(page)
writer.write(output_path)
print(f"Rotated PDF saved to: {output_path}")
def rotate_landscape_pages(
input_path: str,
output_path: str
) -> int:
"""Automatically rotate landscape pages to portrait."""
reader = PdfReader(input_path)
writer = PdfWriter()
rotated_count = 0
for page in reader.pages:
# Get page dimensions
width = float(page.mediabox.width)
height = float(page.mediabox.height)
# Rotate if landscape
if width > height:
page.rotate(90)
rotated_count += 1
writer.add_page(page)
writer.write(output_path)
print(f"Rotated {rotated_count} landscape pages")
return rotated_count
def crop_pages(
input_path: str,
output_path: str,
crop_box: tuple,
pages: Optional[List[int]] = None
) -> None:
"""Crop PDF pages to specified dimensions.
Args:
input_path: Source PDF file
output_path: Destination file
crop_box: (left, bottom, right, top) in points (72 points = 1 inch)
pages: List of page numbers to crop (0-indexed), None for all
"""
reader = PdfReader(input_path)
writer = PdfWriter()
left, bottom, right, top = crop_box
for i, page in enumerate(reader.pages):
if pages is None or i in pages:
page.mediabox = RectangleObject([left, bottom, right, top])
page.cropbox = RectangleObject([left, bottom, right, top])
writer.add_page(page)
writer.write(output_path)
print(f"Cropped PDF saved to: {output_path}")
def scale_pages(
input_path: str,
output_path: str,
scale_x: float = 1.0,
scale_y: float = 1.0
) -> None:
"""Scale PDF pages by specified factors."""
reader = PdfReader(input_path)
writer = PdfWriter()
for page in reader.pages:
# Apply transformation
op = Transformation().scale(sx=scale_x, sy=scale_y)
page.add_transformation(op)
# Update media box
page.mediabox.lower_left = (
float(page.mediabox.lower_left[0]) * scale_x,
float(page.mediabox.lower_left[1]) * scale_y
)
page.mediabox.upper_right = (
float(page.mediabox.upper_right[0]) * scale_x,
float(page.mediabox.upper_right[1]) * scale_y
)
writer.add_page(page)
writer.write(output_path)
print(f"Scaled PDF saved to: {output_path}")
def reorder_pages(
input_path: str,
output_path: str,
new_order: List[int]
) -> None:
"""Reorder PDF pages according to specified order.
Args:
input_path: Source PDF file
output_path: Destination file
new_order: List of page indices in desired order (0-indexed)
"""
reader = PdfReader(input_path)
writer = PdfWriter()
for page_num in new_order:
if 0 <= page_num < len(reader.pages):
writer.add_page(reader.pages[page_num])
writer.write(output_path)
print(f"Reordered PDF saved to: {output_path}")
# Example usage
# rotate_pages('document.pdf', 'rotated.pdf', 90)
# rotate_pages('document.pdf', 'rotated.pdf', 90, pages=[0, 2, 4])
# crop_pages('document.pdf', 'cropped.pdf', (72, 72, 540, 720)) # 1 inch margins
# reorder_pages('document.pdf', 'reordered.pdf', [2, 0, 1, 4, 3])
```Related Skills
llm-wiki-page-shape-contract
Enforce the page-shape contract when a repo-side document or analysis output gets converted into an llm-wiki page. Use when (1) running `scripts/knowledge/llm_wiki.py ingest`, (2) writing or rewriting a wiki page from docs/reports/*, docs/handoffs/*, scripts/review/results/*, or calc citation outputs, (3) deciding whether a page should be split into a folder of sub-pages, (4) reviewing wiki PRs for length / diagram / divide-and-conquer compliance. Codifies the Karpathy + Astro-Han + lewislulu page rules applied to workspace-hub's domain-wiki layout under /mnt/local-analysis/llm-wiki/wikis/<domain>/. Sibling to research/llm-wiki (which owns the CLI ops) — this skill is the quality gate every converted page must clear before commit.
n8n-5-data-transformation-with-code-node
Sub-skill of n8n: 5. Data Transformation with Code Node (+1).
orcawave-aqwa-benchmark-single-page-html-report-structure
Sub-skill of orcawave-aqwa-benchmark: Single-Page HTML Report Structure (+3).
diffraction-analysis-required-report-structure-single-page-html
Sub-skill of diffraction-analysis: Required Report Structure (Single-Page HTML) (+3).
docusaurus-custom-homepage
Sub-skill of docusaurus: Custom Homepage (+1).
pandas-data-processing-3-data-transformation
Sub-skill of pandas-data-processing: 3. Data Transformation.
python-docx-4-headers-footers-and-page-setup
Sub-skill of python-docx: 4. Headers, Footers, and Page Setup.
pypdf-batch-pdf-processing-pipeline
Sub-skill of pypdf: Batch PDF Processing Pipeline.
pypdf-6-encryption-and-form-filling
Sub-skill of pypdf: 6. Encryption and Form Filling.
pypdf-5-text-extraction-and-metadata
Sub-skill of pypdf: 5. Text Extraction and Metadata.
pypdf-4-watermarking-and-stamping
Sub-skill of pypdf: 4. Watermarking and Stamping.
pypdf-2-pdf-splitting
Sub-skill of pypdf: 2. PDF Splitting.