Skip to content
Discussion options

You must be logged in to vote

First you must find an approximate minimum number of lines that will be used for a given box width. Width being 495 we have math.ceil(text_length / 495) is 3.
Then multiply this with the "natural" line height of your font, and again use math.ceil for the result. The natural line height of a font is font.ascender - font.descender. For Times-Roman this is ca. 1.334, so we have

text_length = fitz.get_text_length(text,fontname="tiro")*10
math.ceil(math.ceil(text_length/width)*lineheight)
5

You can also overwrite the font lineheight and e.g. take 1.2.

I called the above "approximate" because the algorithm will start a new line whenever a word will not completely fit in the current line. The qu…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by mohitrobo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants