Agent skill
pypdf-1-memory-management
Sub-skill of pypdf: 1. Memory Management (+2).
Install this agent skill to your Project
npx add-skill https://github.com/vamseeachanta/workspace-hub/tree/main/.claude/skills/_archive/data/office/pypdf/1-memory-management
SKILL.md
1. Memory Management (+2)
1. Memory Management
"""Best practices for handling large PDFs."""
# DO: Process pages one at a time for large files
def process_large_pdf(input_path, output_path):
reader = PdfReader(input_path)
writer = PdfWriter()
for page in reader.pages:
# Process page
writer.add_page(page)
# Writer streams to file, not memory
writer.write(output_path)
# DO: Use context managers when available
with open('document.pdf', 'rb') as f:
reader = PdfReader(f)
# Process...
2. Error Handling
"""Robust error handling for PDF operations."""
from pypdf.errors import PdfReadError, PdfReadWarning
def safe_read_pdf(pdf_path):
"""Safely read PDF with error handling."""
try:
reader = PdfReader(pdf_path)
return reader, None
except PdfReadError as e:
return None, f"Invalid PDF: {e}"
except FileNotFoundError:
return None, f"File not found: {pdf_path}"
except PermissionError:
return None, f"Permission denied: {pdf_path}"
except Exception as e:
return None, f"Unexpected error: {e}"
3. Validation
"""Validate PDF files before processing."""
def validate_pdf(pdf_path):
"""Validate PDF file."""
path = Path(pdf_path)
if not path.exists():
return False, "File does not exist"
if path.suffix.lower() != '.pdf':
return False, "Not a PDF file"
try:
reader = PdfReader(pdf_path)
_ = len(reader.pages) # Try to access pages
return True, "Valid PDF"
except Exception as e:
return False, f"Invalid PDF: {e}"
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
gsd-complete-milestone
Archive completed milestone and prepare for next version
gsd-reapply-patches
Reapply local modifications after a GSD update
gsd-verify-work
Validate built features through conversational UAT
gsd-thread
Manage persistent context threads for cross-session work
clinical-trial-protocol
Generate clinical trial protocols for medical devices or drugs through a modular, waypoint-based architecture with research-only and full protocol modes.
single-cell-rna-qc
Performs quality control on single-cell RNA-seq data (.h5ad or .h5 files) using scverse best practices with MAD-based filtering and comprehensive visualizations.
Didn't find tool you were looking for?