I am trying to extract text from various pdf files depending on font, fontsize and fontstyle, using iText 7.1.14.
public class FontSizeSimpleTextExtractionStrategy : SimpleTextExtractionStrategy
{
FieldInfo _textField = typeof(TextRenderInfo).GetField("text", BindingFlags.NonPublic | BindingFlags.Instance);
public override void EventOccurred(IEventData data, EventType type)
{
if (type.Equals(EventType.RENDER_TEXT))
{
TextRenderInfo renderInfo = (TextRenderInfo)data;
string fontName = renderInfo.GetFont()?.GetFontProgram()?.GetFontNames()?.GetFontName();
iText.Kernel.Colors.Color color = renderInfo.GetFillColor();
float size = renderInfo.GetFontSize();
if (fontName != null)
{
_textField.SetValue(renderInfo, "#Data|" + fontName + "|" + size.ToString() + "|" + ColorToString(color) + "|Data#" + renderInfo.GetText());
}
}
base.EventOccurred(data, type);
}
}
On some files the value of "size" is always "1", although Adobe Acrobat displays the correct font size, which is 25 and 11 in this example file.
Is there any chance to get the correct size with iText?