itextsharp第几页共几页怎么做?

将来现在 将来现在 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
 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());
}

上面是我生成PDF的代码,现在每页只有一个页码,并没有共几页。我要弄成当前第几页和共几页 这个代码要怎么改呢?
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
将来现在
.NET社区 62,275 成员 668,968 内容