iText生产PDF

 //Document:(文档)生成pdf必备的一个对象,生成一个Document示例
                Document document = new Document(PageSize.A4, 30, 30, 5, 5);
                //为该Document创建一个Writer实例:
                PdfWriter.GetInstance(document, new FileStream(@"E:\Chap0103.pdf", FileMode.Create));
                //打开当前Document
                document.Open();
                string fontPath = Environment.GetEnvironmentVariable("WINDIR") + "\\FONTS\\SIMHEI.TTF";//强制中文字体,否则无法显示中文
                BaseFont baseFont = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                BaseFont bf = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                //包含页码没有任何边框的页脚。
                HeaderFooter footer = new HeaderFooter(new Paragraph("This is page: "), true);
                footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
                document.Footer = footer;

                //Chapter对象和Section对象自动构建一个树:
                iTextSharp.text.Font fh = new iTextSharp.text.Font(baseFont, 12);
                iTextSharp.text.Font f1 = new iTextSharp.text.Font(baseFont,10);
                f1.SetStyle(iTextSharp.text.Font.BOLD);
                HeaderFooter hf = new HeaderFooter(new Paragraph("\n\n3月份第二批提貨明細\n\n" + "SKZS-03-2012\n\n" + "作業NO" + "     " + "作業小番\n\n", fh),true);
              
                document.Header = hf;

                Paragraph cTitle = new Paragraph("3月份第二批提貨明細\n\n" + "SKZS-03-2012\n\n" + "作業NO" + "     " + "作業小番\n\n", fh);
                Chapter chapter = new Chapter(cTitle, 1);

                document.Add(chapter);


            table.AddCell(cell);

//f1是字体设置
              cell = new Cell(new Paragraph("钢种", f1));
              table.AddCell(cell);
              cell = new Cell(new Paragraph("炉号", f1));
              table.AddCell(cell);
              cell = new Cell(new Paragraph("厚度", f1));
              table.AddCell(cell);
              cell = new Cell(new Paragraph("定尺", f1));
              table.AddCell(cell);
              cell = new Cell(new Paragraph("捆号", f1));
              table.AddCell(cell);
              cell = new Cell(new Paragraph("捆数", f1));
              table.AddCell(cell);
              cell = new Cell(new Paragraph("支数", f1));
              table.AddCell(cell);
              cell = new Cell(new Paragraph("出库量", f1));
              table.AddCell(cell);

//下面这句话未来以后每页的table都有头
              table.EndHeaders();


   //构建了一个不简单的表:
                               Table table = new Table(3);
                table.BorderWidth = 1;
                table.BorderColor = new iTextSharp.text.Color(0, 0, 255);
                table.Cellpadding = 5;
                table.Cellspacing = 5;
                Cell cell = new Cell("header");
                cell.Header = true;
                cell.Colspan = 3;
                table.AddCell(cell);
                cell = new Cell("example cell with colspan 1 and rowspan 2");
                cell.Rowspan = 2;
                cell.BorderColor = new iTextSharp.text.Color(255, 0, 0);
                table.AddCell(cell);
                table.AddCell("1.1");
                table.AddCell("2.1");
                table.AddCell("1.2");
                table.AddCell("2.2");
                table.AddCell("cell test1");
                cell = new Cell("big cell");
                cell.Rowspan = 2;
                cell.Colspan = 2;
                cell.BackgroundColor = new iTextSharp.text.Color(0xC0, 0xC0, 0xC0);
                table.AddCell(cell);
                table.AddCell("cell test2");
                // 改变了单元格“big cell”的对齐方式:
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                document.Add(table);


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值