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

我去了the documentation并发现了两种方法:rotateClockwiserotateCounterClockwise,尽管他们说参数是 int ,但我无法使其工作。 Python说:

TypeError: unsupported operand type(s) for +: 'IndirectObject' and 'int'

要产生此错误:
page = input1.getPage(i)
page.rotateCounterClockwise(90)
output.addPage(page)

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

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

最佳答案

带有rotateClockwise函数的This is a known bug。尚未合并的There is a fix in place。只需使用此修复程序在pdf.py中编辑'_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)

关于python - 如何在pyPDF2中旋转页面?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42615771/

10-13 07:00
查看更多