如何在 pyPDF2 中旋转页面?

Ign*_*chi 7 python pypdf2

我正在用 pyPDF2 编辑 PDF 文件。我设法生成了我想要的 PDF,但我还没有旋转一些页面。

我去了文档并找到了两种方法:rotateClockwiseand rotateCounterClockwise,虽然他们说参数是int,但我无法让它工作。Python 说:

TypeError: unsupported operand type(s) for +: 'IndirectObject' and 'int'
Run Code Online (Sandbox Code Playgroud)

要产生此错误:

page = input1.getPage(i)
page.rotateCounterClockwise(90)
output.addPage(page)
Run Code Online (Sandbox Code Playgroud)

我找不到解释程序的人。但是,stackoverflow 中有一个问题,但答案很模糊。

提前致谢。对不起,如果我错过了什么。

Nor*_*rsk 5

这是该函数的一个已知错误rotateClockwise这是固定的

pdf.py对于旧版本的 PyPDF2:只需使用此修复程序编辑 '_rotate' 方法即可

def _rotate(self, angle):
    rotateObj = self.get("/Rotate", 0)
    currentAngle = rotateObj if isinstance(rotateObj, int) else rotateObj.getObject()
    self[NameObject("/Rotate")] = NumberObject(currentAngle + angle)
Run Code Online (Sandbox Code Playgroud)

  • 看起来现在已经修复了。 (2认同)