iText7 get table height

人盡茶涼 提交于 2019-12-01 13:10:48

问题


Here is a snippet of my code

Dim table As iText.Layout.Element.Table = New iText.Layout.Element.Table(4)
table.SetWidth(pagesize.GetWidth - 40)
Dim something As Paragraph = New Paragraph("LONG TEXT")

Dim cell as Cell = New Cell().Add(New Paragraph("Some Text").SetFont(timesNewRoman))
table.AddCell(cell)
table.AddCell(cell)
table.AddCell(cell)
table.AddCell(cell)

canvas.Add(table.SetMarginLeft(20))

Dim unit as UnitValue = table.GetHeight()

I always get back nothing as the table height? I don't understand why. Is there a way for me to get the table height? If it makes a difference, this table is in my header, so when I want to set the document margins based on where the table is placed, such that all the text is placed below the header. The text will vary every time I generate this pdf.


回答1:


Dim result As LayoutResult = table.CreateRendererSubTree().SetParent(doc.GetRenderer()).Layout(New LayoutContext(New LayoutArea(1, New Rectangle(0, 0, 400, 10000.0F))))
tableHeight = result.GetOccupiedArea().GetBBox().GetHeight()

This is how I was able to find the table height in itext7, hopefully it can help someone.



来源:https://stackoverflow.com/questions/49287714/itext7-get-table-height

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!