How to write vertically centered text within a given rect? #1662
-
Pretty much the question. The code below automatically places both single- and multiline texts just below the top position (as expected), but I don't know how to adjust it in case I want to vertically center the text. Should I apply a transformation matrix? If so, when? Or should I use the import fitz
doc = fitz.open()
page = doc.new_page()
wrt = fitz.TextWriter(page.rect)
space_available = fitz.Rect(10, 10, page.rect.width-20, 10+page.rect.height/5)
wrt.fill_textbox(space_available, txt, align=1)
page.write_text(writers=wrt)
doc.save("new_doc.pdf") |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Best have a look at this demo script. |
Beta Was this translation helpful? Give feedback.
Best have a look at this demo script.
It fills a textbox and then writes the TextWriter's to several PDF pages in a variety of ways: with rotations, displacements, other colors or transparency, etc. and also inside some given rectangle.