jorisschellekens / borb

borb is a library for reading, creating and manipulating PDF files in python.
https://borbpdf.com/
Other
3.4k stars 147 forks source link

question: center text within TextField? #210

Closed dr-matt closed 2 months ago

dr-matt commented 2 months ago

Setting horizontal_alignment=Alignment.CENTERED of a TextField centers the field itself within the layout, but when the field is filled, the text inside it defaults to left-aligned. Is there a way to center the filled text within the TextField, similar to text_alignment in the Paragraph object?

jorisschellekens commented 2 months ago

Hi @dr-matt ,

I'm afraid such functionality is not provided in borb at this point in time.

You can consult the PDF specification (a copy of which can be found in the repository) to see what the options are.

In the best case scenario, there is some kind of flag you can set to indicate the text justification. In which case you can simply treat the TextField objects as a dictionary and set the flag.

In the worst case, you need to calculate the position of text yourself (by calculating how wide the text is and having the width of the bounding box).

Kind regards, Joris Schellekens

dr-matt commented 1 month ago

@jorisschellekens thank you for the information and for a great library. Cheers!