Does Computing String-Width in PDFbox seem just for character counting?

I have the following problem. I am trying to calculate the line width in a PDFbox to center it in a rectangle. Now my problem is that I get the same width for 12 as for 32, but 1 is less than 3, so my text for 12 is not centered. How can I solve this problem?

Thanks!

+7
source share
2 answers

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; 
+13
source

In some fonts, numbers have the same width. Just try it for different fonts in MSWord, for example. So the fact that you get the same width for 12 and 32 might be correct.

0
source

All Articles