PDF generation renders table bad when spans across pages

I have table that could span across pages. In word rendering everything looks good, but when we render PDF A second table sits on top of a previous table

Snapshot from Word (Good):

Snapshot from PDF (Bad):

I have my sample code here:
ConsoleApp2.zip (16.3 KB)

@leopius In your code you make some of table floating and this causes the problems upon rendering them to PDF. In your case there is no need to use floating tables. Try replacing the following line of code:

table.RelativeHorizontalAlignment = HorizontalAlignment.Center;

with

table.Alignment = TableAlignment.Center;

Also, you set preferred width of some of table to 100%, this is also not required, since you have calculated widths of cells and set them explicitly. I would suggest you to set the following settings after building each table (avoid setting other properties unless you sure they are required):

table.AllowAutoFit = false;
table.Alignment = TableAlignment.Center;
table.AutoFit(AutoFitBehavior.FixedColumnWidths);

You can refactor this into a separate method to avoid code duplication.

Thank you very much for the quick update. I was able to verify that it works

1 Like