【问题标题】:PDFBox: How to get a PDRectangle from a TextPositionPDFBox:如何从 TextPosition 获取 PDRectangle
【发布时间】:2012-07-17 14:10:22
【问题描述】:

我需要用超链接替换现有 PDF 中的某些短语。例如,“使用 Java 语言的一个优势是人力的可用性”应该被处理为“使用the Java language 的一个优势是人力的可用性。”

为此,我创建了一个扩展 PDFTextStripper 的处理器类。通过覆盖processTextPosition,我能够得到所有字符的TextPosition。但我不知道如何从 TextPosition 中获取 PDRectangle,这将帮助我构建 PDAnnotationLink。我尝试了 x、y 属性的组合,但我错过了位置。需要一些帮助。谢谢。

桑杰

【问题讨论】:

    标签: pdfbox


    【解决方案1】:

    我这样做了:

    rectangle.setLowerLeftX(position.getTextPos().getXPosition());
    rectangle.setLowerLeftY(position.getTextPos().getYPosition() - 2); // 2 as cushion
    rectangle.setUpperRightX(rectangle.getLowerLeftX() + position.getWidthDirAdj());
    rectangle.setUpperRightY(rectangle.getLowerLeftY() + 12 /*
        ideally it should be position.getHeightDir()?
        but my sample PDF yielded a negative figure for this */);
    

    【讨论】:

      猜你喜欢
      • 2019-05-31
      • 2015-03-21
      • 2017-03-29
      • 2013-05-10
      • 2018-03-23
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 2016-11-17
      相关资源
      最近更新 更多