iText7 get table height

2019-02-20 21:33发布

问题:

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.



标签: .net itext7