My question is very simple: how can I center a text on a PDF, using PDFBox?
I don’t know the string in advance, I can’t find the middle by trial. The string doesn’t always have the same width.
I need either:
- A method that can center the text, something like
addCenteredString(myString) - A method that can give me the width of the string in pixels. I can then calculate the center, for I know the dimensions of the PDF.
Any help is welcome!
Ok, I found the answer myself. Here is how to center some text on a page: