【问题标题】:Get absolute bounding box of Chunk in iText 2.1.7?在 iText 2.1.7 中获取 Chunk 的绝对边界框?
【发布时间】:2012-07-30 19:18:14
【问题描述】:

在这个例子中:

Document document=new Document();
PdfWriter.getInstance(document,new FileOutputStream("hello.pdf"));
document.open();  
Paragraph paragraph = new Paragraph();
paragraph.add(new Chunk("Hello ");
paragraph.add(new Chunk("world");
paragraph.add(new Chunk(" in");
paragraph.add(new Chunk(" iText 2.7.1");
document.add(paragraph);
document.close(); 

如何获取第二块“世界”页面的绝对位置、宽度和高度?换句话说,就是用户空间的边界框。

【问题讨论】:

  • never 是 iText 的 2.7.1 版本。你是说2.1.7吗?
  • 现在在文本中更正为 2.1.7。谢谢亚历克西斯。

标签: pdf-generation itext


【解决方案1】:

您可以使用 Chunks 上提供的通用标签工具。

    public class PEvents extends PdfPageEventHelper {
      @Override
      public void onGenericTag(PdfWriter w, Document doc, Rectangle r, String tag) {
         if (tag.equals("mytag")) {             
           //here r is the rectangle of "world" chunk
         }
      }
    }
    writer.setPageEvent(new PEvents());
    Chunk world = new Chunk("world");
    world.setGenericTag("mytag");
    paragraph.add(world);
    . . .

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 2020-12-08
    • 2015-03-14
    相关资源
    最近更新 更多