itextsharp第几页共几页怎么做?

将来现在 2011-12-19 02:35:07
 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的代码,现在每页只有一个页码,并没有共几页。我要弄成当前第几页和共几页 这个代码要怎么改呢?
...全文
226 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
将来现在 2011-12-20
  • 打赏
  • 举报
回复
太冷清了,等了一天,结果没人。
蝶恋花雨 2011-12-20
  • 打赏
  • 举报
回复
http://www.cnblogs.com/CareySon/category/332146.html 翻译的看看有没有帮助,
建议用PDFViewerNET40x86这个
laoyingisme 2011-12-20
  • 打赏
  • 举报
回复
这段代码让我想起了export to excel成几个Sheet,好像比较难!
将来现在 2011-12-19
  • 打赏
  • 举报
回复
来人撒,杂这么冷清呢。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧