I want to write a simple program that asks the user to open a PDF file from any location, add image A to any page that contains the keywords "Orange County", and add image B to any page that contains the keywords "Hillsborough county", then save the new file at the same location as the old PDF file.
Below is what I have so far, but I kept getting the error "AttributeError: 'Document' object has no attribute 'searchFor'"
main_win.sourceFile = filedialog.askopenfilename(parent=main_win, initialdir= "/", title='Please select the PDF file for conversion')
document = fitz.open(main_win.sourceFile)
page = document
if main_win.sourceFile:
dst_pdf_filename = 'destination.pdf'
img_filename1 = 'Orange county stamp.png'
img_filename2 = 'Hillsborough county stamp.png'
img_rect = fitz.Rect(55, 28, 180, 390)
text = page.searchFor("")
for page in main_win.sourceFile:
if text == "Orange county":
page.insertImage(img_rect, filename=img_filename1)
if text == "Hillsborough county":
page.insertImage(img_rect, filename=img_filename2)
document.save(dst_pdf_filename)
document.close()