PDF文件中较低索引的字母(如j,p,q,g等)的大小问题

时间:2018-12-10 18:14:47

标签: pdf itext

尊敬的堆栈溢出成员...

我尝试用PDF覆盖单词。 我选择了一个单词:“ informacji”,将从整个PDF文件中删除。 问题是在这种情况下,我无法获得正确大小的字母:“ j”。 enter image description here

更聪明的人可能会弄乱后面写的东西。

我实现了从LocationTextExtractionStrategy继承的我自己的类,这是代码:

 public override void RenderText(TextRenderInfo renderInfo)
    {
        LineSegment segment = renderInfo.GetBaseline();
        if (renderInfo.GetRise() != 0)
        { // remove the rise from the baseline - we do this because the text from a super/subscript render operations should probably be considered as part of the baseline of the text the super/sub is relative to 
            Matrix riseOffsetTransform = new Matrix(0, -renderInfo.GetRise());
            segment = segment.TransformBy(riseOffsetTransform);
        }
       var fnt= renderInfo.GetFont();

        TextChunk tc = new TextChunk(renderInfo.GetText(), tclStrat.CreateLocation(renderInfo, segment));
        Vector startLine = renderInfo.GetBaseline().GetStartPoint();
        Vector endLineTopRight = renderInfo.GetAscentLine().GetEndPoint();
        Rectangle textRectangle = new Rectangle(startLine[Vector.I1], startLine[Vector.I2], endLineTopRight[Vector.I1], endLineTopRight[Vector.I2]);
        TextInfo textInfo = new TextInfo(tc, textRectangle);
        locationalResult.Add(textInfo);
    }

和稍后的几行代码,我将textRectangle对象的值添加到对象wordList[wordList.Count-1].rectanglesToDraw.Add(new SquaresToDraw(page, text.textRectangle.Left, text.textRectangle.Bottom, text.textRectangle.Right, text.textRectangle.Top));的列表中

现在附加信息(没有特别的imo):

RectanglesToDrawSquaresToDraw

的列表

SquaresToDraw是一个类,看起来像:

 public class SquaresToDraw
{
    public int pageNumber { get; set; }
    public float left { get; set; }//llx
    public float bottom { get; set; }  //lly
    public float right { get;set;} //rux
    public float top { get; set; }//ruy
    public SquaresToDraw(int pageNumber,float left, float bottom, float right,float top)
    {
        this.pageNumber = pageNumber;
        this.left = left;
        this.right = right;
        this.bottom = bottom;
        this.top = top;
    }
}

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

您使用基线添加矩形的下限:

Vector startLine = renderInfo.GetBaseline().GetStartPoint();

如果您也想用基线以下部分覆盖字母,则应改用下降线:

Vector startLine = renderInfo.GetDescentLine().GetStartPoint();