You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Damien Dudouit <dd...@clio.ch> on 2014/03/25 09:38:37 UTC

FontBox, howto: TrueTypeFont.getWidth(String text, float fontSize)

Hello,

First of all, thanks a lot for PdfBox. It's great.

I need to measure text with some TrueTypeFont. Would someone indicate me
the actual code to do the following :

TrueTypeFont ttfFont = TrueTypeFont .load(File file)

float width = ttfFont.getWidth(String text, float fontSize)

ttfFont.getKerning(int char1, int char2)

Thanks in advance,

Damien

Re: FontBox, howto: TrueTypeFont.getWidth(String text, float fontSize)

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi Damien,

FontBox is a low level library helping you to get the font data such as character maps or glyph widths for different font types. There are no functions to get the data you are looking for directly. I think the easiest is to look at PDSimpleFont and PDTrueTypeFont within org.apache.pdfbox.pdmodel.font which reads the basic data and generates additional information needed to handle your request.

Hope this gives you a start. If there are further questions let us know.

BR
Maruan Sahyoun


Am 25.03.2014 um 09:38 schrieb Damien Dudouit <dd...@clio.ch>:

> Hello,
> 
> First of all, thanks a lot for PdfBox. It's great.
> 
> I need to measure text with some TrueTypeFont. Would someone indicate me
> the actual code to do the following :
> 
> TrueTypeFont ttfFont = TrueTypeFont .load(File file)
> 
> float width = ttfFont.getWidth(String text, float fontSize)
> 
> ttfFont.getKerning(int char1, int char2)
> 
> Thanks in advance,
> 
> Damien