iText7获取表格高度 [英] iText7 get table height

查看:422
本文介绍了iText7获取表格高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码段

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()

我总是一无所获,因为桌子的高度是多少?我不明白为什么.有没有办法让我提高桌子的高度?如果有所不同,则此表位于我的标题中,因此当我要基于放置表格的位置设置文档边距时,将所有文本都放置在标题下方.每次我生成此pdf文件时,文本都会有所不同.

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.

推荐答案

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()

这就是我能够在itext7中找到桌子高度的方式,希望它可以对某人有所帮助.

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

这篇关于iText7获取表格高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆