I've the following issue. I try to calculate the width of a string in PDFbox to center it in a rectangle. Now my problem is, that I get the same width for 12 as for 32, but the 1 is smaller than the 3 so that my text is for 12 not centered. How can I solve this issue?
Thanks!
From this question:
PDFont font = PDType1Font.HELVETICA_BOLD; // Or whatever font you want.
int fontSize = 16; // Or whatever font size you want.
float width = font.getStringWidth(text.substring(start,i)) / 1000 * fontSize;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With