Is it possible to execute QPDF through Python script

这一生的挚爱 提交于 2019-12-23 22:24:14

问题


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.


回答1:


Thanks to furas for pointing me in the right direction.

This is how I did it in Windows 10:

  1. 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.
  2. 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"])


来源:https://stackoverflow.com/questions/40619482/is-it-possible-to-execute-qpdf-through-python-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!