mariem
mariem

Reputation: 21

Java iText - Get Font size and family of a text selected from a pdf file

I'm writing to inquire a bout a problem when I'm using iText library to extract text contents from PDF file.I would able to extract all the text, but couldn't find the method to extract font styles.

Upvotes: 1

Views: 1779

Answers (2)

KimvdLinde
KimvdLinde

Reputation: 617

To get the fontsize of a font in itext, use this code:

renderInfo.getAscentLine().getStartPoint().get(1)-
renderInfo.getDescentLine().getStartPoint().get(1)

This will give you the exact fontsize.

Upvotes: 1

Bruno Lowagie
Bruno Lowagie

Reputation: 77576

First you need to read the answer to this question: how can i get text formatting with iTextSharp

In this question, you'll discover that the TextRenderInfo has a getFont() method that allows you to get the PostScriptFontName. If you are in luck, this PostScriptFontName will give you information about the style.

Note that this won't always work. Please read the answer to this question: What are the ways of checking if piece of text in PDF documernt is bold using iTextSharp

That question shows an example of a font that doesn't reveal anything about its style.

Upvotes: 1

Related Questions