简体   繁体   English

将 PDF 相对于当前旋转旋转 90 度

[英]rotate PDF 90 degrees relative to current rotation

I have rotated a PDF using fitz by 90 degrees using this code:我使用以下代码将使用 fitz 的 PDF 旋转了 90 度:

fitz_doc = fitz.open(origin, filetype="pdf")
fitz_doc_name = f"{fitz_doc.name}.pdf"

page = fitz_doc[int(0)]
page.setRotation(90)
fitz_doc.save(fitz_doc_name)
fitz_doc.close()

However, if I want to rotate the document again by another 90 degrees, I have to set page.setRotation to 180 and not 90. I suspect this has to do with how the 3x3 Matrix values are being manipulated but not sure if that is correct or how to manipulate the values directly.但是,如果我想再次将文档再旋转 90 度,我必须将page.setRotation设置为 180 而不是 90。我怀疑这与 3x3 矩阵值的操作方式有关,但不确定这是否正确或如何直接操作值。

How can I rotate a document relative to the current rotation so that if a document was previously rotated by 90 I only need to set rotation value to 90 and not 180 for the second rotation?如何相对于当前旋转旋转文档,以便如果文档先前旋转了 90,我只需将旋转值设置为 90 而不是 180 进行第二次旋转?

I'm not sure there's a direct way to do this.我不确定是否有直接的方法可以做到这一点。 Instead, you get the current rotation value and then add to it how much more you want to rotate.相反,您获取当前的旋转值,然后向其中添加您想要旋转的数量。

more_rot = 90  # extra rotation desired
current_rot = page.rotation
page.setRotation(current_rot + more_rot)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM