Kyl*_*yle 20 c# pdf itext width
我正在尝试使用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 ( );
Run Code Online (Sandbox Code Playgroud)
我正在设置表格的宽度,以便它应该扩展页面的边距.但是当创建pdf时,表格只占边距之间的80%.我在这里做错了吗?
Kyl*_*yle 33
弄清楚了.显然table.Width是百分比而不是宽度(以像素为单位).所以使用:
table.Width = 100;
Run Code Online (Sandbox Code Playgroud)
工作就像一个魅力.