如何在pyPDF2中旋转页面?

时间:2017-03-06 00:27:24

标签: python pypdf2

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

我去了the documentation并找到了两种方法:CREATE TABLE MEI_Tbl ( MEI_ID int PRIMARY KEY IDENTITY (1,1), SRC tinyint NOT NULL DEFAULT '2', HEI_ID AS (Cast (SRC as varchar)+ Cast (MEI_ID as varchar)) ); rotateClockwise,虽然他们说参数是 int ,但我无法制作这行得通。 Python说:

rotateCounterClockwise

产生此错误:

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

我找不到有人解释这个程序。但是,堆栈溢出中有question,但答案很简单。

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

2 个答案:

答案 0 :(得分:3)

带有rotateClockwise功能的

This is a known bug。尚未合并的There is a fix in place。只需编辑' _rotate'使用此修补程序的pdf.py中的方法

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

答案 1 :(得分:0)

尝试用以下方法替换你的三行:

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

我认为必须对getPage调用进行旋转,而不是“提取”页面。

相关问题