#!/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_simple(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}") # 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 using built-in font insertion_point = fitz.Point(inst.x0, inst.y1 - 1) # Slightly above baseline try: page.insert_text( insertion_point, "02/2001 - 11/2003", fontsize=9, color=(0, 0, 0) # Black text ) except Exception as e: print(f"Error inserting text: {e}") # Try with a different approach page.insert_textbox( inst, "02/2001 - 11/2003", fontsize=9, color=(0, 0, 0), align=0 # left align ) if not text_found: print("Target text '02/2001 - 11/2002' was not found in the PDF") # Save the modified PDF doc.save(output_path) doc.close() print(f"Modified PDF saved to: {output_path}") if __name__ == "__main__": edit_pdf_text_simple("Ryan_Malloy_Resume_corrected_simple.pdf")