我在下面有这段代码,请帮我在每一页中重复表格标题。我在网上尝试了几个可用的选项,但它们不起作用。我是第一次使用 ItextSharp。谢谢
int columns = gv.Columns.Count;
int rows = gv.Rows.Count;
int tableRows = rows + 3;
string flName = "";
if (gv.ID == "gvShares")
{
flName = "Share_Statement.pdf";
}
if (gv.ID == "gvSavingAccStmt")
{
flName = "Main_Saving_Account_Statement.pdf";
}
Document Doc = new Document();
PdfWriter.GetInstance(Doc, Response.OutputStream);
Doc.Open();
BaseFont bfTimes = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false);
Font times = new Font(bfTimes, 9, Font.NORMAL, Color.BLACK);
//string imageFilePath = HttpContext.Current.Server.MapPath("/Image/Sacco_Logo.jpg");
string test = System.Web.HttpContext.Current.Server.MapPath(".");
string substr = test.Remove(test.Length - 6);
//string imageFilePath = "\\app\\Image\\Sacco_Logo.jpg";//"\\app\\Image\\Sacco_Logo.jpg";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(substr + "\\Image\\Sacco_Logo.jpg");
//Resize image depend upon your need
jpg.ScaleToFit(75f, 75f);
jpg.SpacingAfter = 10f;
jpg.Alignment = Element.ALIGN_LEFT;
//Doc.Add(jpg);
PdfPTable table = new PdfPTable(1);
table.DefaultCell.Border = PdfPCell.NO_BORDER;
table.WidthPercentage = 100;
PdfPCell cell = new PdfPCell( table.DefaultCell);
cell.Border = PdfPCell.BOTTOM_BORDER;
cell.PaddingBottom = 5;
Phrase phrase = new Phrase();
phrase.Add(new Chunk(jpg, 0, 0));
phrase.Add(new Chunk("Kenya Diaspora Sacco"));
cell.AddElement( phrase );
table.AddCell(cell);
Doc.Add(table);
Phrase phrNewLine = new Phrase("\n");
Doc.Add(phrNewLine);
Paragraph TitlePhrasePh = new Paragraph("Membership Savings Account Statement", times);
TitlePhrasePh.SetAlignment("Center");
Doc.Add(TitlePhrasePh);
Doc.Add(phrNewLine);
Paragraph PhUsername = new Paragraph("Name: " + Username, times);
PhUsername.SetAlignment("Left");
Doc.Add(PhUsername);
Paragraph PhAccount = new Paragraph("Account Number: " + AccountNumber, times);
PhAccount.SetAlignment("Left");
Doc.Add(PhAccount);
iTextSharp.text.Table gridViewTable = new iTextSharp.text.Table(columns, tableRows);
gridViewTable.BorderWidth = 1;
gridViewTable.BorderColor = new Color(0, 0, 255);
gridViewTable.Cellpadding = 1;
gridViewTable.Cellspacing = 1;
gridViewTable.AddCell(new Paragraph("Date", times));
gridViewTable.AddCell(new Paragraph("Type", times));
gridViewTable.AddCell(new Paragraph("Description", times));
if (gv.ID == "gvShares")
{
gridViewTable.AddCell(new Paragraph("Sell[KHSH]", times));
}
gridViewTable.AddCell(new Paragraph("Debit[KHSH]", times));
if (gv.ID == "gvShares")
{
gridViewTable.AddCell(new Paragraph("Buy[KHSH]", times));
}
gridViewTable.AddCell(new Paragraph("Credit[KHSH]", times));
if (gv.ID == "gvShares")
{
gridViewTable.AddCell(new Paragraph("Balance", times));
}
else if (gv.ID == "gvSavingAccStmt")
{
gridViewTable.AddCell(new Paragraph("Balance[KHSH]", times));
}
for (int rowCounter = 0; rowCounter < rows; rowCounter++)
{
for (int columnCounter = 0; columnCounter < columns; columnCounter++)
{
string strValue = gv.Rows[rowCounter].Cells[columnCounter].Text;
gridViewTable.AddCell(new Paragraph(strValue, times));
}
}
Doc.Add(gridViewTable);
Doc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=" + flName);
Response.End();