我正在尝试创建一个具有页眉和页脚的pdf生成器,并且该pdf的内容中有一个表格。该表可以包含未知数量的行,并且可以生成多个页面。他发出错误的声音,在桌子下面。
public static void Gerar(List<string> listaNutrientesGrupo)
{
Eventos ev = new Eventos();
Document document = new Document();
document.SetPageSize(PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("C:\\Projetos\\teste.pdf", FileMode.Create));
writer.PageEvent = ev;
document.Open();
//Success - With text works normally
//for (int i = 0; i < 100; i++)
//{
// document.Add(new Paragraph("Test line", new Font(iTextSharp.text.Font.FontFamily.COURIER, 7, (int)System.Drawing.FontStyle.Regular)));
//}
//Error
PdfPTable t = new PdfPTable(1);
for (int i = 0; i < 100; i++)
{
t.AddCell(new PdfPCell(new Phrase("test test test", new Font(iTextSharp.text.Font.FontFamily.COURIER, 7, (int)System.Drawing.FontStyle.Regular))));
}
document.Add(t);
document.Close();
}
class Eventos : PdfPageEventHelper
{
public override void OnStartPage(PdfWriter writer, Document document)
{
Paragraph ph = new Paragraph("Test header Pdf", new Font(iTextSharp.text.Font.FontFamily.COURIER, 8, (int)System.Drawing.FontStyle.Bold));
document.Add(ph);
ph = new Paragraph("Test test test pdf pdf pdf", new Font(iTextSharp.text.Font.FontFamily.COURIER, 8, (int)System.Drawing.FontStyle.Regular));
document.Add(ph);
ph = new Paragraph();
iTextSharp.text.pdf.draw.VerticalPositionMark seperator = new iTextSharp.text.pdf.draw.LineSeparator();
ph.Add(seperator);
ph.Add(new Chunk("\n"));
ph.Add(new Chunk("\n"));
document.Add(ph);
}
}