python调用q脚本_是否可以通过Python脚本执行QPDF

I'm working on a python script that processes PDF files, though some of them contain encryption that restricts usage to only printing, which I have to manually remove before I can process them.

For that I have been manually using QPDF to remove these restrictions on individual PDF files before running the script (the commands for qpdf are pretty simple...inside the command prompt -> qpdf --decrypt input.pdf output.pdf)

My question is - rather than doing this bit manually, is it possible to execute the QPDF executable file within my Python script and run the command? I haven't been able to find any python modules specifically to control QPDF so I am not holding much hope.

解决方案

Thanks to furas for pointing me in the right direction.

This is how I did it in Windows 10:

Download QPDF, extract the folder and save somewhere on your PC. I put the folder in C:\qpdf-5.1.2. Inside the folder is bin\qpdf.exe.

Set an environment variable to C:\qpdf-5.1.2\bin. To set an environment variable in Windows 10, go to System Properties > Advanced > Environment Variables. With PATH highlighted, click Edit, then click New and paste in the path to the directory in point 2.

Once that is set up, you can reference 'qpdf' in the command prompt and in Python.

import subprocess

subprocess.run(["qpdf", "--decrypt", "C:/qpdf-5.1.2/bin/input.pdf", "C:/qpdf-5.1.2/bin/output.pdf"])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值