我正在尝试通过打开 PDF、添加文本框并保存来向 pdf 添加文本。当我运行代码时,什么也没有发生。在桌面上,它显示文件已更新,但没有显示任何文本。
这是代码:
import fitz
doc = fitz.open("/Users/khaylablack/Desktop/participant_certificate.pdf")
page = doc[0] # choose some page
rect = fitz.Rect(50, 100, 200, 200) # rectangle (left, top, right, bottom) in pixels
text = "absolutely not"
rc = page.insertTextbox(rect, text, fontsize = 48, # choose fontsize (float)
fontname = "Times-Roman", # a PDF standard font
fontfile = None, # could be a file on your system
align = 1) # 0 = left, 1 = center, 2 = right
#doc.saveIncr() # update file. Save to new instead by doc.save("new.pdf",...)
doc.save("/Users/khaylablack/Desktop/watermarked_participant_cert.pdf")