Skip to content

Question: How to add widgets / PDF form fields to rotated PDFs? #1837

Answered by JorjMcKie
MrVonkey asked this question in Q&A
Discussion options

You must be logged in to vote

I regret to say that this is not supported.
There is an annotation flag however (fields in fact are annotations), that prevents rotation even when the page is rotated: the annot's top-left rectangle point will remain fixed.
So you can try this:

import fitz
doc=fitz.open()
page=doc.new_page()
r=fitz.Rect(100,300,200,330)
w=fitz.Widget()
w.rect=r
w.field_type=fitz.PDF_WIDGET_TYPE_TEXT
w.field_value="Mary"
w.text_fontsize=11
w.field_name="textfield"
annot=page.add_widget(w)
annot.flags
4
annot.set_flags(4 | 2**4)
page.set_rotation(90)
doc.ez_save("x.pdf")

But different PDF viewers behave differently. I haven't any doing what you expect. SumatraPDF (Windows) displays it correctly, but does no…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@MrVonkey
Comment options

Answer selected by MrVonkey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1834 on July 25, 2022 21:04.