iTextSharp 笔记

 

 

Paragraph 报表中的文本
Image 报表中的图片
PdfPTable 表格
PdfPCell 单元格

1. 添加table元素到PDF文件当中:

   PdfPTable table = new PdfPTable(5);   //括号当中的数字代表列数

   table.SetWidths(new int[] { 15, 40, 15,15, 15 });    //设置各列的宽度比例

   table.WidthPercentage = 100;                                //table的宽度

   1.1 table当中添加元素我们可以这样加,好处是可以设置元素的的样式:

         PdfPCell cell = new PdfPCell(new Phrase("Artikelcode", fontTableHeader));

          cell.HorizontalAlignment = Element.ALIGN_CENTER; //让文本居中显示

          // cell.BorderWidth = 0;                //设置表格边框宽度为0

    1.2 table.AddCell(cellArtikel);     1.3 table.AddCell("colspan 1");

    1.4 table.AddCell(new Phrase("subtotaal", fontChinese));   //此时可以套用字体样式

    1.5 PdfPCell cell = new PdfPCell(new Phrase(" Header spanning 68 columns 这是汉字楷体 ", fontChinese));

         BaseFont bfchinese = BaseFont.CreateFont(@"c:\windows\fonts\kaiu.ttf",   BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); 

         Font fontChinese = new Font(bfchinese, 12, Font.ITALIC, BaseColor.RED);

          Font fontChinese2 = new Font(bfchinese, 12, Font.NORMAL, new BaseColor(0, 0, 0)); //黑 

          //Font fontChinese = new Font(bfChinese, 12, Font.NORMAL,new Color(0, 255, 0)); //绿

     1.6 table也可以嵌套table:

         table.AddCell(table1);   //table1元素添加跟前面介绍的一样。

二、纸张设置

      Document document = new Document(PageSize.A5,36, 72,108,180);  

      Document document = new Document(PageSize.A4.Rotate(), -90, -90, 60, 10);   //横放

 

posted @ 2016-12-18 21:16  一枚水  阅读(193)  评论(0编辑  收藏  举报