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 s
When using writeSelectedRows()
, it doesn't make sense to set the width percentage to 100%. Setting the width percentage is meant for when you add a document using document.add()
(which is a method you can't use in a page event). When using document.add()
, iText calculates the width of the table based on the page size and the margins.
You are using writeSelectedRows()
, which means you are responsible to define the size and the coordinates of the table.
If you want the table to span the complete width of the page, you need:
table.TotalWidth = document.Right - document.Left;
You're also using the wrong X-coordinate: you should use document.Left
instead of 150
.
Additional info:
writeSelectedRows()
that expects 7 parameters).PdfContentByte
instance. This is the canvas on which you're drawing the table.