3

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.

Carlos Laspina
  • 2,013
  • 4
  • 27
  • 44

1 Answers1

6

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);
Alexey Subach
  • 11,903
  • 7
  • 34
  • 60