62,046
社区成员
发帖
与我相关
我的任务
分享
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 = Element.ALIGN_CENTER;
aTable.AddCell(cell);
cell = new iTextSharp.text.Cell(new Paragraph("单位", font));
cell.Header = true;
cell.Colspan = 2;
cell.Rowspan = 1;
cell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
cell.VerticalAlignment = 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 = 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 = Element.ALIGN_CENTER;
aTable.AddCell(cell);
cell = new iTextSharp.text.Cell(new Paragraph("联系人", font));
cell.Header = true;
cell.Colspan = 2;
cell.Rowspan = 1;
cell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
cell.VerticalAlignment = 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 = 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 = Element.ALIGN_CENTER;
aTable.AddCell(cell);
cell = new iTextSharp.text.Cell(new Paragraph("名称", font));
cell.Header = true;
cell.Colspan = 1;
cell.Rowspan = 1;
cell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
cell.VerticalAlignment = Element.ALIGN_CENTER;
aTable.AddCell(cell);
// datatable.Rows.InsertAt(dr, 0);
cell = new iTextSharp.text.Cell(new Paragraph("账号", font));
cell.Header = true;
cell.Colspan = 1;
cell.Rowspan = 1;
cell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
cell.VerticalAlignment = Element.ALIGN_CENTER;
aTable.AddCell(cell);
cell = new iTextSharp.text.Cell(new Paragraph("姓名", font));
cell.Header = true;
cell.Colspan = 1;
cell.Rowspan = 1;
cell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
cell.VerticalAlignment = Element.ALIGN_CENTER;
aTable.AddCell(cell);
cell = new iTextSharp.text.Cell(new Paragraph("电话", font));
cell.Header = true;
cell.Colspan = 1;
cell.Rowspan = 1;
cell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
cell.VerticalAlignment = Element.ALIGN_CENTER;
aTable.AddCell(cell);
//设置每页表头
aTable.EndHeaders();
//aTable.TableFitsPage = true;
// datatable.Rows.InsertAt(dr, 0);
//PdfPTable table = new PdfPTable(datatable.Columns.Count);
for (int i = 0; i < datatable.Rows.Count; i++)
{
for (int j = 0; j < datatable.Columns.Count; j++)
{
font = new iTextSharp.text.Font(bfChinese, 9);
aTable.AddCell(new Paragraph(datatable.Rows[i][j].ToString(), font));
}
}
//table.TotalWidth =
document.Add(aTable);
PdfContentByte cb = writer.DirectContent;
ColumnText ct = new ColumnText(cb);
ct.SetSimpleColumn(new Phrase("This header is only on right hand pages"), 60, 300, 100, 500, 15, Element.ALIGN_CENTER);
ct.Go();
document.Close();
string Url = ConfigurationManager.ConnectionStrings["xzUrl"].ConnectionString;
Response.Redirect(Url);
}
catch (DocumentException de)
{
document.Close();
Response.Write(de.ToString());
}