#!/usr/bin/env python3 import sys import os # Add the virtual environment to the path sys.path.insert(0, '/home/rpm/claude/ryanmalloy.com/static-files/documents/pdf_env/lib/python3.12/site-packages') import fitz # PyMuPDF import urllib.request def edit_pdf_text_advanced(output_path): """Edit PDF text using PyMuPDF to correct the Intouch Solutions end date.""" print("Downloading original PDF from static server...") urllib.request.urlretrieve("https://static.ryanmalloy.com/documents/Ryan_Malloy_Resume.pdf", "original_resume.pdf") # Open the PDF doc = fitz.open("original_resume.pdf") print(f"PDF has {len(doc)} pages") text_found = False # Process each page for page_num in range(len(doc)): page = doc.load_page(page_num) print(f"Processing page {page_num + 1}") # Get text instances to find and replace text_instances = page.search_for("02/2001 - 11/2002") if text_instances: print(f"Found target text on page {page_num + 1}") text_found = True # For each instance found for inst in text_instances: print(f"Found text at position: {inst}") # Remove the old text by covering it with a white rectangle page.add_redact_annot(inst, fill=(1, 1, 1)) # White fill # Apply the redaction page.apply_redactions() # Add the corrected text # Get the font information from nearby text point = fitz.Point(inst.x0, inst.y0 + (inst.y1 - inst.y0) * 0.8) # Adjust vertical position # Insert the corrected text page.insert_text(point, "02/2001 - 11/2003", fontsize=10, color=(0, 0, 0)) # Black text if not text_found: print("Target text '02/2001 - 11/2002' was not found in the PDF") # Let's search for similar patterns for page_num in range(len(doc)): page = doc.load_page(page_num) text = page.get_text() if "Intouch Solutions" in text: print(f"Found 'Intouch Solutions' on page {page_num + 1}") print("Text around Intouch Solutions:") lines = text.split('\n') for i, line in enumerate(lines): if "Intouch Solutions" in line: # Print surrounding lines for context start = max(0, i-2) end = min(len(lines), i+3) for j in range(start, end): prefix = ">>> " if j == i else " " print(f"{prefix}{lines[j]}") break # Save the modified PDF doc.save(output_path) doc.close() print(f"Modified PDF saved to: {output_path}") if __name__ == "__main__": edit_pdf_text_advanced("Ryan_Malloy_Resume_corrected_fitz.pdf")