日期:2014-05-18 浏览次数:20633 次
Document document = new Document(new Rectangle(850, 595)); try { BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); Font fontChinese = new Font(bfChinese, 10, Font.NORMAL, new Color(0, 0, 0)); //按设置的字体输出文本 string strPath = Page.MapPath(@"File") + "\\核实报表.pdf"; PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(strPath, FileMode.Create)); HeaderFooter footer = new HeaderFooter(new Phrase("This is page: "), true); footer.Border = Rectangle.NO_BORDER; document.Footer = footer; document.Open(); //document.Add(new Paragraph(this.TextBox1.Text.ToString(), fontChinese)); //输出图片到PDF文件 //iTextSharp.text.Image jpeg01 = iTextSharp.text.Image.GetInstance(Server.MapPath("../Images/biaogetou.jpg")); //document.Add(jpeg01); //iTextSharp.text.Image jpeg02 = iTextSharp.text.Image.GetInstance(Server.MapPath("../Images/book_addresses.png")); //document.Add(jpeg02); BaseFont bfSun1 = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font font = new iTextSharp.text.Font(bfSun1, 13); Paragraph blahblah = new Paragraph("--", font); blahblah.Alignment = Element.ALIGN_CENTER; document.Add(blahblah); font = new iTextSharp.text.Font(bfSun1, 13); blahblah = new Paragraph("--", font); blahblah.Alignment = Element.ALIGN_LEFT; blahblah.Font = font; document.Add(blahblah); DataTable datatable = scPdfTable(); //DataRow dr = datatable.NewRow(); //dr[0] = "核实时间"; //dr[1] = "核实事项"; //dr[2] = "单位名称"; //dr[3] = "账号"; //dr[4] = "凭证号码"; //dr[5] = "金额"; //dr[6] = "联系人姓名"; //dr[7] = "联系人电话"; //dr[8] = "确认结果"; //dr[9] = "经办人"; iTextSharp.text.Table aTable = new iTextSharp.text.Table(10); // 4 rows, 4 columns aTable.Border = iTextSharp.text.Rectangle.NO_BORDER; aTable.BorderWidth = 1; aTable.Width = 98; float[] headerwidths = { 20, 20, 40, 19, 19, 15, 8, 12, 8, 8 }; aTable.Widths = headerwidths; aTable.WidthPercentage = 100; aTable.DefaultHorizontalAlignment = Element.ALIGN_CENTER; aTable.DefaultVerticalAlignment = Element.ALIGN_CENTER; aTable.AutoFillEmptyCells = true; //设置表头 aTable.Cellpadding = 1; aTable.Cellspacing = 0; aTable.BorderWidth = 1; aTable.TableFitsPage = true; font = new iTextSharp.text.Font(bfSun1, 9); iTextSharp.text.Cell cell = new iTextSharp.text.Cell(new Paragraph("核实时间", font)); cell.Header = true; cell.Colspan = 1; cell.Rowspan = 2; cell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; cell.VerticalAlignment = Element.ALIGN_CENTER; // Cell.setAlignment(Element.ALIGN_CENTER); aTable.AddCell(cell); cell = new iTextSharp.text.Cell(new Paragraph("核实事项", font)); cell.Header = true; cell.Colspan = 1; cell.Rowspan = 2; cell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; cell.VerticalAlignment = Elem