问题描述
我正在处理可处理PDF文件的python脚本,尽管其中一些文件包含加密功能,将加密限制为仅用于打印,在处理它们之前,我必须手动将其删除.
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.
为此,在运行脚本之前,我一直手动使用 QPDF 来消除对单个PDF文件的这些限制(qpdf的命令非常简单...在命令提示符内-> qpdf --decrypt input.pdf output.pdf)
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)
我的问题是-是否可以在我的Python脚本中执行QPDF可执行文件并运行命令,而不是手动执行此操作?我还没有找到专门用于控制QPDF的python模块,所以我抱的希望不大.
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.
推荐答案
感谢 furas 在右边指向我方向.
Thanks to furas for pointing me in the right direction.
这是我在Windows 10中所做的:
This is how I did it in Windows 10:
- 下载 QPDF ,解压缩该文件夹并将其保存在PC上的某个位置.我将文件夹放在C:\ qpdf-5.1.2.文件夹内是bin \ qpdf.exe.
- 将环境变量设置为C:\ qpdf-5.1.2 \ bin.要在Windows 10中设置环境变量,请转到系统属性>高级>环境变量.在"PATH"突出显示的情况下,单击编辑",然后单击新建",然后粘贴到第2点中目录的路径.
- 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.
设置完成后,您可以在命令提示符和Python中引用"qpdf".
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"])
这篇关于是否可以通过Python脚本执行QPDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!