我正在尝试使用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%的空间,我是不是做错了什么?
发布于 2010-10-18 23:02:24
在iTextSharp最新版本(5.0.4)中,PdfPTable
具有WidthPercentage
属性。
要设置静态值,该属性为TotalWidth
。
发布于 2009-09-26 12:56:01
我想通了。显然,table.Width
是百分比,而不是像素宽度。所以使用:
table.Width = 100;
就像一个护身符。
发布于 2017-05-26 19:19:08
用户还可以按百分比设置表格宽度。
t.WidthPercentage = 100f;
https://stackoverflow.com/questions/1481139
复制相似问题