使用 python 和 pdftk 自动密码锁定 PDF 时遇到的问题

问题描述

我正在尝试使用 python 和 pdftk 密码锁定 PDF Python 生成一个 pw 然后使用 pdftk 锁定 pdf,然后创建一个带有路径名和密码的 excel 文件

https://pastebin.com/F07Q9njf

什么有效?

什么不起作用?

  • 我似乎找不到密码锁定的 PDF
try:
    directory=sys.argv[1]
except:
    directory=r"C:\Users\Desktop\UNMOD"


outputdir = directory
print(outputdir)
if not os.path.exists(outputdir):
    os.makedirs(outputdir)

print("Working on files in [",directory,"] :") 
for filename in os.listdir(directory):
    if filename.endswith(".pdf"):
        filename_noext = os.path.splitext(filename)[0]
        filename_encrypted = outputdir + filename_noext + "_encrypted.pdf"
        password = id_generator()
        subprocess.run(["pdftk",filename,"output",filename_encrypted,"user_pw",password]) 
        print("Encrypting [ ",os.path.join(directory,filename)," ] to [ "," ] with password: ",password)
        df.loc[len(df.index)] = [filename_encrypted,password]
        continue
    else:
        continue

writeExcel() 

我认为错误在这里?或者有没有其他解决方案可以解决我的问题(即其他语言、批处理文件等,只要它们是免费的)

请帮忙!提前致谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)