问题
In the previous version of itext (5.5.x) I used the BaseFont
class as follows:
BaseFont bf = BaseFont.createFont ("Arial.ttf", BaseFont.WINANSI, true);
Then used the method getWidthPoint
bf.getWidthPoint (TEXT_EXAMPLE, fontSize);
But in the version of itext 7 I am not finding the BaseFont
class and also some utility that allows me to get the withPoint of a certain text.
Any help is welcome.
回答1:
To create a similar font in iText7
, use:
PdfFont font = PdfFontFactory.createFont("Arial.ttf", PdfEncodings.WINANSI, true);
To get the width of a certain String
, use:
float width = font.getWidth(TEXT_EXAMPLE, fontSize);
来源:https://stackoverflow.com/questions/43919397/how-get-the-widthpoint-in-itext7