QPDF 在 python 中给出找不到文件的错误

QPDF giving file not found error in python

我正在使用 qpdf 解密 pdf 文件(已加密但没有密码),因为 pypdf2 解密不起作用。 它在命令行上工作,但 python 给出 FileNotFoundError

qpdf --decrypt --replace-input test.pdf # it's working; replacing test.pdf with the absolute path

但是对于 python 它不会

inp_file = open(self.path, "rb")
inp_pdf = PdfFileReader(inp_file)
if inp_pdf.isEncrypted:
    try:
        inp_pdf.decrypt('')
    except:
        subprocess.run(["qpdf", "--decrypt", "--replace-input", self.path)])

我切换到pikepdf。它建立在 QPDF 之上;下面引号中的简要说明。基于现有 pdf 创建新 pdf 非常简单。此外,它还可以即时处理解密。

Pikepdf provides a Pythonic wrapper around the C++ PDF content transformation library, QPDF.

它没有实现从pdf中提取文本;我使用 tika 进行文本提取。