#!/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 def fix_intouch_start_date(input_path, output_path): """Fix Intouch Solutions start date from 02/2001 to 05/2002.""" # Open the PDF doc = fitz.open(input_path) 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}") # Look for the specific text pattern "02/2001 - 11/2003" text_instances = page.search_for("02/2001 - 11/2003") 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}") # Create a white rectangle to cover the old text white_rect = fitz.Rect(inst.x0, inst.y0, inst.x1, inst.y1) page.draw_rect(white_rect, color=None, fill=(1, 1, 1), width=0) # Insert the corrected text at the same position insertion_point = fitz.Point(inst.x0, inst.y1 - 1) try: page.insert_text( insertion_point, "05/2002 - 11/2003", fontsize=9, color=(0, 0, 0) ) print("Successfully replaced with 05/2002 - 11/2003") except Exception as e: print(f"Error inserting text: {e}") if not text_found: print("Target text '02/2001 - 11/2003' was not found in the PDF") # Let's check what Intouch-related text exists 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}") lines = text.split('\n') for i, line in enumerate(lines): if "Intouch Solutions" in line: start = max(0, i-1) 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__": fix_intouch_start_date("Ryan_Malloy_Resume.pdf", "Ryan_Malloy_Resume_date_fixed.pdf")