I am working with iTextSharp trying to add an header and a footer to my generated PDF but, if I try to add an header that have width of 100% of my page I have some problem.
So I have do the following things:
1) I have create a class named PdfHeaderFooter that extends the iTextSharp PdfPageEventHelper class
2) Into PdfHeaderFooter I have implemented the OnStartPage() method that generate the header:
// write on start of each page
public override void OnStartPage(PdfWriter writer, Document document)
{
base.OnStartPage(writer, document);
PdfPTable tabHead = new PdfPTable(new float[] { 1F });
PdfPCell cell;
//tabHead.TotalWidth = 300F;
tabHead.WidthPercentage = 100;
cell = new PdfPCell(new Phrase("Header"));
tabHead.AddCell(cell);
tabHead.WriteSelectedRows(0, -1, 150, document.Top, writer.DirectContent);
}
If I use sometning like tabHead.TotalWidth = 300F; insted tabHead.WidthPercentage = 100; it work well but if I try to set as 100% the width of the tabHead table (as I do in the previous example) when it call the tabHead.WriteSelectedRows(0, -1, 150, document.Top, writer.DirectContent) method it throw the following exception:
The table width must be greater than zero.
Why? What is the problem? How is it possible that the table have 0 size if I am setting it to 100%?
Someone can help me to solve this issue?
Tnx