【问题标题】:Get Coordinates and write on them获取坐标并在上面写
【发布时间】:2020-02-13 19:51:34
【问题描述】:

我正在通过以下代码提取 (X & Y) 坐标

TextPosition.getXDirAdj() 和 TextPosition.getYDirAdj()

输出是:-

    for Char "1" X= 79.0 and Y= 31.0 

但是正确的坐标是 X=79 和 Y = 760

为什么会这样,我该如何解决。

【问题讨论】:

    标签: pdfbox


    【解决方案1】:

    TextPosition.getXDirAdj()TextPosition.getYDirAdj() 不返回默认用户空间坐标系中的坐标,而是返回 PDFBox 文本剥离内部使用的坐标系中的坐标,以便更轻松地确定文本行。

    要检索默认用户空间坐标系中的坐标,请使用文本矩阵的TranslateXTranslateY 属性,并添加当前页面裁剪框左下角的坐标。

    例如对于TextPosition textpositionPDRectangle cropBox

    float x = textposition.getTextMatrix().getTranslateX() + cropBox.getLowerLeftX();
    float y = textposition.getTextMatrix().getTranslateY() + cropBox.getLowerLeftY();
    

    通常裁剪框的左下角为 (0, 0),因此通常不需要使用裁剪框进行校正。不过,对于需要更正的示例,请参阅 this answer

    【讨论】:

      猜你喜欢
      • 2016-05-11
      • 2019-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多