2017-03-06 163 views
2

我正在用pyPDF2編輯PDF文件。我設法生成我想要的PDF,但我還沒有旋轉一些頁面。如何在pyPDF2中旋轉頁面?

我去the documentation,發現兩種方法:rotateClockwiserotateCounterClockwise,雖然他們說的參數是INT,我不能使它發揮作用。蟒蛇說:

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

爲了產生這種錯誤:

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

我找不到別人解釋的過程。但是,在計算器中有question,但答案只是模糊不清。

在此先感謝。對不起,我錯過了什麼。

回答

3

This is a known bugrotateClockwise函數。尚未合併的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) 
0

嘗試用這種替代你的三條線:

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

我覺得旋轉也要做一個GETPAGE呼叫而不是「提取」頁面上。