Closed andi-dev closed 1 year ago
When you invoke Page#rotate
, the flatten
argument means that the rotation is done by incorporating it into the content stream instead of using the /Rotate
key. This involves the manipulation of the page boxes and additions to the content stream. When you rotate the page by 90 degree, the following happens (where 0
marks the origin of the coordinate system):
d-----c
| |
| |
| |
0-----b
--->
c-----------b
| |
| |
d-----------0
The annotations of a page, however, are currently not rotated which means that they stay where the are, in the upper right quadrant whereas the page now lives in the upper left quadrant. And form fields are represented by widget annotations.
Also see https://github.com/gettalong/hexapdf/issues/188
The best way currently to avoid problems is to flatten all annotations before rotating the page, i.e. first doc.acro_form.flatten
to flatten form fields (and possibly generate the appearances in the first place) followed by page.flatten_annotations
and then the rotation.
Ok, thank you for pointing this out, I would have missed to call page.flatten_annotations
before flattening the rotation.
@andi-dev Due to my recent work in this area I also have a draft solution for this problem. I will finish this before the next release.
@andi-dev I have implemented annotation rotation, so your stated use case now works correctly. Due to another change involving the rotation of form fields, the filling out the rotated PDF still works correctly, i.e. the changed form field entries appear rotated.
Hi again :)
While trying to reproduce a different bug, I ran into this issue:
doc.pages.first.rotate(90, flatten: true)
doc.write("rotated.pdf")
Apparently rotate with
flatten: true
is flattening the form, which is fine for us. However, if I first callacro_form.flatten
and thendoc.pages.first.rotate(90, flatten: true)
the field values do not get lost, so I assume there is something different between what rotate withflatten: true
does with the form, compared toacro_form.flatten
.Tested with
master
anddevel
branches.Let me know If I can provide any more information.