如何在pyPDF2中旋转页面?

2024-10-01 17:41:08 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我去了the documentation,发现了两个方法:rotateClockwise和{},虽然他们说参数是一个int,但我无法使其工作。Python说:

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

要产生此错误:

^{pr2}$

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

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


Tags: 文件the方法编辑参数pdfdocumentation页面
2条回答

尝试用以下内容替换三行:

output.addPage(input1.getPage(i).rotateCounterClockwise(90))

我认为轮换必须在getPage调用上完成,而不是在“extracted”页面上。在

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

相关问题 更多 >

    热门问题