ItextSharp 获取表高度,行高度

集合表

private PdfPTable GetListRows(List<OutShowReportDetailDto> list)
        {
            PdfPTable table = new PdfPTable(6);
            table.TotalWidth = pdfContentWidth;
            int indexRow = 0;
            for (int i = 0; i < 9; i++)
            {
                list.ForEach(x =>
                {
                    AddCellValue(table, x.TestName, indexRow);
                    AddCellValue(table, x.TestMothed, indexRow);
                    AddCellValue(table, x.Result, indexRow);
                    AddCellValue(table, x.Unit, indexRow);
                    AddCellValue(table, x.HLFlag, indexRow);
                    AddCellValue(table, x.ReferenceRange, indexRow);
                    indexRow += 1;
                });
            }
            return table;
        }

 

集合总高度

 1  private float CalculatePdfPTableHeight(PdfPTable table)
 2         {
 3             using (MemoryStream ms = new MemoryStream())
 4             {
 5                 using (Document doc = new Document(PageSize.TABLOID))
 6                 {
 7                     using (PdfWriter w = PdfWriter.GetInstance(doc, ms))
 8                     {
 9                         doc.Open();
10                         table.WriteSelectedRows(0, table.Rows.Count, 0, 0, w.DirectContent);
11                         doc.Close();
12                         return table.TotalHeight;
13                     }
14                 }
15             }
16         }

 行高度

pdfPTable.GetRowHeight(index);//index 是集合索引

 

posted @ 2020-11-23 09:49  jasonlai2016  阅读(667)  评论(0编辑  收藏  举报