【发布时间】:2016-06-20 15:56:02
【问题描述】:
我想得到以下单元格的高度。
cell_logo
单元格标题
cell_version
cell_dateTime
cell_appVersion
但 cell_name.Height 返回 0 。如何获得这些单元格的实际高度?
PdfPTable table = new PdfPTable(1);
table.TotalWidth = doc.PageSize.Width - doc.LeftMargin - doc.RightMargin;
table.LockedWidth = true;
PdfPCell cell_logo = new PdfPCell(imgLog);
cell_logo.HorizontalAlignment = 1;
cell_logo.BackgroundColor = new BaseColor(System.Drawing.Color.White);
cell_logo.PaddingBottom = 20;
cell_logo.PaddingTop = 50;
PdfPCell cell_title = new PdfPCell(docName);
cell_title.HorizontalAlignment = 1;
cell_title.BackgroundColor = new BaseColor(System.Drawing.Color.White);
cell_title.PaddingBottom = 50;
PdfPCell cell_versions = new PdfPCell(ssVersions);
cell_versions.BackgroundColor = new BaseColor(System.Drawing.Color.White);
cell_versions.PaddingTop = 5;
cell_versions.PaddingBottom = 5;
PdfPCell cell_dateTime = new PdfPCell(time);
cell_dateTime.BackgroundColor = new BaseColor(System.Drawing.Color.White);
cell_dateTime.PaddingTop = 5;
cell_dateTime.PaddingBottom = 5;
PdfPCell cell_appVersion = new PdfPCell(SSCGVersion);
cell_appVersion.BackgroundColor = new BaseColor(System.Drawing.Color.White);
cell_appVersion.MinimumHeight = doc.PageSize.Height - doc.TopMargin - doc.BottomMargin - cell_logo.Height - cell_title.Height - cell_versions.Height - cell_dateTime.Height;
table.AddCell(cell_logo);
table.AddCell(cell_title);
table.AddCell(cell_versions);
table.AddCell(cell_dateTime);
table.AddCell(cell_appVersion);
doc.Add(table);
其实我想设置表格高度等于页面大小
【问题讨论】:
-
unable to calculate itext PdfPTable/PdfPCell height properly 的可能重复项。您需要像these examples 那样向表格询问行高。高度单元本身无关紧要。重要的是单元格所属行的高度。另见How to make a footer stick to bottom of every pdf page?
标签: c# pdf height itextsharp cell