import fitz # Import PyMuPDF def overlay_notes(original_pdf_path, notes_pdf_path, output_pdf_path): # Open the original and notes documents original_pdf = fitz.open(original_pdf_path) notes_pdf = fitz.open(notes_pdf_path) # Iterate through the pages and overlay notes onto the original for page_number in range(len(original_pdf)): original_page = original_pdf[page_number] if page_number < len(notes_pdf): # Check if there's a corresponding notes page notes_page = notes_pdf[page_number] # Create a pixmap of the notes page with an alpha channel (transparency) pixmap = notes_page.get_pixmap(alpha=True) # Insert the pixmap onto the original page original_page.insert_image(original_page.rect, pixmap=pixmap) # Save the modified document to a new file original_pdf.save(output_pdf_path) # File paths original_pdf_path = '1.pdf' notes_pdf_path = '2.pdf' output_pdf_path = 'merged_output.pdf' # Function call to overlay the notes overlay_notes(original_pdf_path, notes_pdf_path, output_pdf_path)