问题
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!
回答1:
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;
回答2:
In some fonts the numbers do all 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 could be correct.
来源:https://stackoverflow.com/questions/13701017/calculation-string-width-in-pdfbox-seems-only-to-count-characters