mergeRotatedTranslatedPage doubt #903
Replies: 7 comments 14 replies
-
What do you mean by that? |
Beta Was this translation helpful? Give feedback.
-
I too have some problems understanding how excatcly this function works. When I am trying to center a landscape page which I rotated to portrait on a bigger page I am absolutley unable to do it as I have no idea what way I need to translate it. I tried to understand the translation matrix that is applied but I was unable to grasp the concept fully. |
Beta Was this translation helpful? Give feedback.
-
I do not know the origin of the PDF that you use, per do you make a recommendation, use the gs command to clean inconsistent info containing the PDF before using py-pdf2
|
Beta Was this translation helpful? Give feedback.
-
Test.pdf |
Beta Was this translation helpful? Give feedback.
-
The rotation with from PyPDF2 import Transformation, PdfReader, PdfWriter
reader = PdfReader("box.pdf")
page = reader.pages[0]
x1, y1, x2, y2 = page.cropbox
assert x1 == 0
assert y1 == 0
op = Transformation().rotate(rotation=180).translate(tx=x2, ty=y2)
page.add_transformation(op)
print(page.cropbox)
print(page.mediabox)
writer = PdfWriter()
writer.add_page(page)
with open("output.pdf", "wb") as fp:
writer.write(fp) The center point of the coordinates is in the bottom-left corner. That means if you want to flip the image by 180 degrees, the content would go from the upper-right quadrant to the lower-left one. You can see that those are just simple coordinate transformations. PyPDF2 does not care for this operation where the actual content is. It also doesn't care about the mediabox / cropbox / trimbox. It just applies the transformation to the coordinate system. Did that clarify the topic? |
Beta Was this translation helpful? Give feedback.
-
I thought about creating two more convenience methods for
Would that be useful? Do you have an opinion on the naming of those functions? Which media- |
Beta Was this translation helpful? Give feedback.
-
The "minimal example" from earlier in this thread seems to be a broken link. |
Beta Was this translation helpful? Give feedback.
-
Hello everyone
I can't understand what the process is like when applying page1.mergeRotatedTranslatedPage (page2, ...)
Assuming the two pages of equal size
The following works well:
This works fine
more or less it comes out as I want but not as well as I wish
Could someone please explain this to me?
Thank you
Beta Was this translation helpful? Give feedback.
All reactions