【问题标题】:iTextSharp: A long cell starts to new page even if there's space in current pageiTextSharp:即使当前页面有空间,长单元格也会开始到新页面
【发布时间】:2019-07-16 10:58:08
【问题描述】:

我有一个包含 2 个单元格的 PDFPTable。 第一个有 1 行。第二个有 100 行。 第二个单元格进入新页面,但我希望它在第一个单元格之后开始。

        Dim cFile As String = "c:\temp\ccc.pdf"

        Dim doc = New Document(PageSize.A4)
        Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(cFile, FileMode.Create))
        doc.Open()
        Dim oPdf As PdfContentByte = writer.DirectContent


        Dim baseFont As BaseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, False)
        Dim baseFontBold As BaseFont = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, False)

        Dim courier As New Font(baseFont, 12)
        Dim bold As New Font(baseFontBold, 12, Font.Bold, Color.RED)

        Dim tb0 As New PdfPTable(1)
        Dim cell0 As New PdfPCell
        Dim ch0 As New Chunk("AA")
        Dim ph0 As New Phrase(ch0)
        cell0.AddElement(ph0)
        tb0.AddCell(cell0)

        'Dim tb1 As New PdfPTable(1)
        Dim cell1 As New PdfPCell
        For i = 1 To 100
            Dim ch1 As New Chunk("CIAO")
            Dim ph1 As New Phrase(ch1)
            cell1.AddElement(ph1)

        Next

        tb0.AddCell(cell1)


        doc.Add(tb0)
        'doc.Add(tb1)


        doc.Close()

我希望第二个单元格保留在第一页,但实际转到新页面

【问题讨论】:

  • 我的回答对您有足够的帮助吗?还是还有未解决的问题?

标签: vb.net itext


【解决方案1】:

将你桌子上的SplitLatetb0设置为False,即添加

tb0.SplitLate = False

之前

doc.Add(tb0)

如果SplitLateTrue(默认情况下),iText 会尝试通过尽可能长时间地推迟拆分来防止不必要地拆分表格行,即将它们拆分尽可能迟到。特别是,如果一个新行从一个已经有内容的页面开始并且该行不完全适合,iText 首先开始一个新页面并在新页面上绘制该行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多