vb.net - iTextSharp:即使当前页面有空间,长单元格也会开始到新页面
问题描述
我有一个带有 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()
我希望第二个单元格保留在第一页但实际转到新页面
解决方案
SplitLate
在你的桌子tb0
上设置False
,即添加
tb0.SplitLate = False
前
doc.Add(tb0)
如果SplitLate
是True
(默认情况下),iText 尝试通过尽可能长时间地推迟拆分来防止不必要地拆分表行,即尽可能晚地拆分它们。特别是,如果新行从已经有内容的页面开始并且该行不完全适合,iText 首先开始一个新页面并在新页面上绘制该行。
推荐阅读
- playframework - 如何为 ok()、status() 等不同方法导入 play framework 的 Results 类
- flutter - Flutter 中的凹陷或深度效果
- python - KeyError: 'x' 不断阻止我的代码工作
- reactjs - React:使用 axios 将 FormData 发送到 API
- javascript - React.js:如何获取剪贴板数据并使用带有地图功能的图像和文本显示在主页上
- vmware - Windows 10 VMware VM 未从 GNS 3 云获取 IP
- javascript - 使用 new Date() 和时间的函数
- datagrip - 按多列对数据视图中的结果集进行排序
- javascript - 未处理的承诺拒绝:TypeError:未定义不是对象(评估'userLocation.coords.latitude')
- github - 拉取请求的状态检查通过或失败时如何获得通知?