Я создаю PDF-файл с таблицей. Эта таблица занимает несколько страниц. Я хочу вставить HeaderRow один раз на каждой странице. На форуме я уже нашел команду pdfPTable. setHeaderRows (1). Но это приводит к ошибке. PdfPTable не содержит определения для setHeaderRows.
private void Cmd_Protocoll_Click(object sender, EventArgs e)
{
Document pProtocoll = new Document(iTextSharp.text.PageSize.A4.Rotate(), 10, 10, 10, 10);// A4 Querformat
PdfWriter.GetInstance(pProtocoll, new FileStream("TestPDF.pdf", FileMode.Create));
pProtocoll.Open();
pProtocoll.SetPageSize(PageSize.A4.Rotate());
pProtocoll.AddTitle("PDF-Erstellung");
string author = Txt_PreName.Text + Txt_LastName.Text;
pProtocoll.AddAuthor(author);
pProtocoll.AddSubject("Was ist das Subject");
/*BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
iTextSharp.text.Font font = FontFactory.GetFont(iTextSharp.text.Font.FontFamily.TIMES_ROMAN.ToString(), 6,
iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);*/
PdfPTable pdfPTable = new PdfPTable(7);
pdfPTable.setHeaderRow(1);
pdfPTable.TotalWidth = 750f;
pdfPTable.LockedWidth = true;
float[] widths = new float[] { 3f, 1f, 1f, 5f, 1f, 1f, 0.75f };
pdfPTable.SetWidths(widths);
PdfPCell cell = new PdfPCell(new Phrase("Prüfprotokol zum Hardwaredatenpunkttest"));
cell.Colspan = 3;
cell.HorizontalAlignment = 1;
BaseFont btnColumnHeader = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font fntColumnHeader = FontFactory.GetFont(iTextSharp.text.Font.FontFamily.TIMES_ROMAN.ToString(), 10,
iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
for(int i =0; i < Dgv_Data_List.Columns.Count; i++)// Einlesen der Kopfzeile
{
PdfPCell headerCell = new PdfPCell();
headerCell.BackgroundColor = iTextSharp.text.BaseColor.YELLOW;
headerCell.AddElement(new Chunk(Dgv_Data_List.Columns[i].HeaderText, fntColumnHeader));
pdfPTable.AddCell(headerCell);
}
BaseFont btnColumnData = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font fntColumnData = FontFactory.GetFont(iTextSharp.text.Font.FontFamily.TIMES_ROMAN.ToString(), 8,
iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
for (int i = 0; i < Dgv_Data_List.Rows.Count; i++) // einfügen der Tabelle
{
for(int j = 0; j < Dgv_Data_List.Columns.Count; j++)
{
PdfPCell dataCell = new PdfPCell();
dataCell.BackgroundColor = iTextSharp.text.BaseColor.WHITE;
dataCell.AddElement(new Chunk(Dgv_Data_List.Rows[i].Cells[j].Value.ToString(), fntColumnData));
pdfPTable.AddCell(dataCell);
}
}
pdfPTable.setHeaderRows(1);
pProtocoll.Add(pdfPTable);
pProtocoll.Close();
}