【问题标题】:itextsharp: detecting if text / images are not fitting on pageitextsharp:检测文本/图像是否不适合页面
【发布时间】:2009-12-21 17:14:36
【问题描述】:

我正在使用 itextsharp 在 vb.net 中生成报告。有时整个报告不适合一页,我需要知道 itextsharp 何时将页面添加到文档中。有没有办法检测到这一点?

【问题讨论】:

    标签: vb.net pdf itextsharp


    【解决方案1】:

    只要您实现PdfPageEvent 接口,您只需要覆盖public void onEndPage(PdfWriter writer, Document document) 方法,该方法在新页面启动之前调用。

    编辑:这里有一些解释该过程的代码,不知道如果 iTextSharp 创建了一个新页面你想做什么,这是我能给你的最多的:

    Public Class YourReport
      Implements PdfPageEvent
    
      'Your report code
    
      Public Overrides Sub onEndPage(ByVal writer as PdfWriter, 
                                           ByVal doc as Document)
        'if you get here, a new page was created by iTextSharp 
        'so do what you need to do.
      End Sub
    
    End Class
    

    【讨论】:

    • 覆盖 Sub onEndPage(ByVal writer 作为 PdfWriter,ByVal doc 作为 Document)
    • 不,它仍然会生成一个新页面,但您会在onEndPage 中检测到它,然后您可以做出相应的反应。
    • 澄清一下,您正在类的顶部实现PdfPageEvent 接口,使用Public Class YourReport Implements PdfPageEvent 之类的东西,对吗?
    • 您需要将onEndPage 添加到您的班级。它是 iTextSharp 库的 PdfPageEvent 接口的一部分,因此除非您添加它,否则您不会通过字符串搜索找到它。
    • 您应该将代码放在您创建的 onEndPage 覆盖中。当 iTextSharp 写完一个页面时它会被击中。
    猜你喜欢
    • 1970-01-01
    • 2010-10-28
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-03
    • 1970-01-01
    • 2013-11-11
    相关资源
    最近更新 更多