C# - 从PDF单字符获取文本高度

时间:2017-02-01 10:28:51

标签: c# pdf itext

我需要从pdf中提取的字符文本高度。 我有以下内容,只是不知道如何获得文本高度。

static class Program
{
    static void Main()
    {
        PdfReader reader = new PdfReader("C:\\temp\\TestDrawing.pdf");
        var s = PdfTextExtractor.GetTextFromPage(reader, 1, new LocationTextExtractionStrategy(new my()));
    }
}

public class my : LocationTextExtractionStrategy.ITextChunkLocationStrategy
{

    public LocationTextExtractionStrategy.ITextChunkLocation CreateLocation(TextRenderInfo renderInfo, LineSegment baseline)
    {

        foreach (TextRenderInfo tr in renderInfo.GetCharacterRenderInfos())
        {
            LineSegment bl = tr.GetBaseline();
            string text = tr.GetText(); //gets text charactor 
            float startpointX = bl.GetStartPoint()[Vector.I1]; 
            float startpointY = bl.GetStartPoint()[Vector.I2];
            float endpointX = bl.GetEndPoint()[Vector.I1];
            float endpointY = bl.GetEndPoint()[Vector.I2];
            //now need to get the height of the text
        }
        return new LocationTextExtractionStrategy.TextChunkLocationDefaultImp(baseline.GetStartPoint(), baseline.GetEndPoint(), renderInfo.GetSingleSpaceWidth());
    }
}

0 个答案:

没有答案