我正在尝试通过打开 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")
HUX布斯
牧羊人nacy
相关分类