使用PDFNetPython3替换PDF中的文本-不工作



这是一个应该替换PDF文件中的文本的函数。没有显示错误,但是文本没有在输出文件中被替换。与输入文件相同。会出什么问题呢?

import sys
from PDFNetPython3 import *
input_path = "D:\Users\admin\Desktop\"
output_path = "D:\Users\admin\Desktop\"            
def changeText():
PDFNet.Initialize()
doc = PDFDoc(input_path + "input.pdf")
doc.InitSecurityHandler()
replacer = ContentReplacer()
page = doc.GetPage(1)
replacer.AddString("Old_content","New_content")
replacer.Process(page)
doc.Save(output_path +"sample.pdf", SDFDoc.e_linearized)
doc.Close()
print("File Saved")
changeText()

PDFNetPython3仅支持到python 3.8。你运行的是什么版本的python ?

最新更新