Csharp/C#教程:iTextSharp表格宽度为页面的100%分享


iTextSharp表格宽度为页面的100%

我正在尝试使用iTextSharp为文档添加表格。 这是一个例子:

Document document = new Document(PageSize.LETTER,72, 72, 72, 72); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("C:\test.pdf", FileMode.Create)); document.Open(); Table table = new Table ( 2, 1 ); table.Width = document.RightMargin - document.LeftMargin; // Cell placeholder Cell cell = new Cell ( new Paragraph ( "Some Text" ) ); table.AddCell ( cell ); cell = new Cell ( new Paragraph ( "More Text" ) ); table.AddCell ( cell ); document.Add ( table ); document.Close ( ); 

我正在设置表格的宽度,以便它应该扩展页面的边距。 但是当创建pdf时,表只占据边距之间约80%的空间。 我在这里做错了吗?

在iTextSharp最新版本(5.0.4)中, PdfPTable具有WidthPercentage属性。

要设置静态值,属性为TotalWidth

弄清楚了。 显然table.Width是百分比而不是宽度(以像素为单位)。 所以使用:

 table.Width = 100; 

工作就像一个魅力。

用户还可以按百分比设置表格宽度。

 t.WidthPercentage = 100f; 

iText7中不再提供WidthPercentage属性。 请改用以下内容

上述就是C#学习教程:iTextSharp表格宽度为页面的100%分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 table.SetWidth(new UnitValue(UnitValue.PERCENT, 100)); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1023674.html

(0)
上一篇 2022年1月7日
下一篇 2022年1月7日

精彩推荐