【问题标题】:How to re-position an iTextSharp ColumnText after testing with Go(True)?使用 Go(True) 测试后如何重新定位 iTextSharp ColumnText?
【发布时间】:2013-10-13 16:42:19
【问题描述】:

我正在为处理垂直对齐的 ColumnText 编写一个小包装器 - 即。在边界框内顶部/中间/底部对齐。

当我调用SetSimpleColumn 时,它需要边界框的位置。调用Go(True)(true = 测试模式)可以让我测试文本的高度。从那里,我想重新分配 Y 坐标,因此当我调用 Go() 时,文本会显示在所需的新位置。如果可能,如何实现?

编:示例:

Imports iTextSharp.text
...

columnText = New pdf.ColumnText(pageContentByte)
columnText.SetSimpleColumn(New Phrase("some text"), x1, y1, x2, y2, leading)
columnText.Go(True) ' Test mode.'
y1 = y2 + (y1 - columnText.yLine) ' Bottom-align it.'
''
' HOWTO: Re-position Y-coordinate (y1) of columnText object?'
''
columnText.Go()     ' Render at adjusted Y position.'

(在 cmets 末尾添加单引号以使语法高亮正常工作)

【问题讨论】:

    标签: vb.net pdf-generation itextsharp


    【解决方案1】:

    SetSimpleColumn() 设置的变量受到保护,因此您无法直接访问它们。但是,您应该能够通过更新的参数重新使用 SetSimpleColumn() 方法。

    columnText.SetSimpleColumn(New Phrase("some text"), x1, y1, x2, y2, leading)
    columnText.Go(True) ''//Test mode.
    
    y1 = y2 + (y1 - columnText.yLine) ''// Bottom-align it.
    
    columnText.SetSimpleColumn(New Phrase("some text"), x1, y1, x2, y2, leading)
    columnText.Go(False) ''// Render at adjusted Y position.
    

    【讨论】:

    • 谢谢,我最终这样做了,但想知道是否有一种不涉及重复主代码的“更简洁”的方式。尝试了一个自定义的“MyColumnText”类,覆盖了 Go(),但是,无论我调整了什么受保护的成员,它似乎都没有影响任何东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    • 2014-10-22
    • 1970-01-01
    相关资源
    最近更新 更多