How get the widthPoint in itext7

荒凉一梦 提交于 2020-12-12 02:03:41

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!