How to add a table as a header?

こ雲淡風輕ζ 提交于 2019-12-02 10:40:01

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:

  • The first two parameters define the start row and the end row. In your case, you start with row 0 which is the first row, and you don't define an end row (that's what -1 means) in which case all rows are drawn.
  • You omitted the parameters for the columns (there's a variation of the writeSelectedRows() that expects 7 parameters).
  • Next you have the X and Y value of start coordinate for the table.
  • Finally, you pass a PdfContentByte instance. This is the canvas on which you're drawing the table.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!