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

标签 pdf itext

亲爱的 Stack Overflow 成员(member)...

我尝试覆盖 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.文本矩形.左,文本.文本矩形.底部,文本.文本矩形.右,文本.文本矩形.顶部));

现在附加信息(在我看来没什么特别的):

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;
    }
}

任何帮助将不胜感激。

最佳答案

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

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

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

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

关于pdf - PDF 文件中较低索引字母(如 : j, p、q、g 等)的大小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53711387/

相关文章:

c# - 保存前预览 PDF

java - 保护从 iTextPdf 生成的 PDF

button - itext PushbuttonField 行为

c# - 使用 iTextSharp 从 PDF 中删除水印

java - iText:提取图像时出错 - 在 LZWDecoder 中获取 NullPointerException

c# - 我们如何使用 iTextSharp 将数据表导出为 PDF?

php - 使用 FPDF 在单元格中自动换行?

java - 使用pdfbox从PDF文件中提取文本

ios - 如何呈现 PDF 表单供用户填写?

java - 如何将 List<PdfDocument> 合并到单个 PdfDocument