@maik.manke
Hi, I’ve checked the issue
The issue appears to be caused by mixed RowSpan/ColSpan handling when later rows omit cells that are still occupied by previous row spans. As a workaround, define all 8 cells in each physical row and hide internal borders for the cells that should visually span. Also make sure the page/content width is large enough for the total column width.
The following code seems to address the issue
Public Sub TableRowspanColspanLayoutIssue()
Dim originalOutputPath As String = "table_rowspan_colspan_original_out.pdf"
Dim fixedOutputPath As String = "table_rowspan_colspan_fixed_out.pdf"
Using originalDoc As New Document()
originalDoc.PageInfo.IsLandscape = True
Dim page As Page = originalDoc.Pages.Add()
page.Paragraphs.Add(CreateCustomerSpannedTable())
originalDoc.Save(originalOutputPath)
End Using
Using fixedDoc As New Document()
fixedDoc.PageInfo.IsLandscape = True
fixedDoc.PageInfo.Margin = New MarginInfo With {
.Left = 10,
.Right = 10,
.Top = 10,
.Bottom = 10
}
Dim page As Page = fixedDoc.Pages.Add()
page.Paragraphs.Add(CreateCustomerSpannedTableWithBorderWorkaround())
fixedDoc.Save(fixedOutputPath)
End Using
End Sub
Private Function CreateCustomerSpannedTable() As Table
Dim table As New Table With {
.ColumnAdjustment = ColumnAdjustment.Customized,
.ColumnWidths = "68 125 160 27 75 75 45 215",
.DefaultCellBorder = New BorderInfo(BorderSide.All, 0.75F, Color.Red)
}
Dim row As Row = table.Rows.Add()
Dim cell As Cell = row.Cells.Add("1/1")
cell.RowSpan = 3
row.Cells.Add("1/2")
cell = row.Cells.Add("1/3")
cell.RowSpan = 3
cell = row.Cells.Add("1/4")
cell.ColSpan = 5
row = table.Rows.Add()
cell = row.Cells.Add("2/1")
cell.RowSpan = 2
row.Cells.Add("2/2")
row.Cells.Add("2/3")
row.Cells.Add("2/4")
row.Cells.Add("2/5")
cell = row.Cells.Add("2/6")
cell.RowSpan = 2
row = table.Rows.Add()
cell = row.Cells.Add("3/1")
cell.ColSpan = 4
Return table
End Function
Private Function CreateCustomerSpannedTableWithBorderWorkaround() As Table
Dim table As New Table With {
.ColumnAdjustment = ColumnAdjustment.Customized,
.ColumnWidths = "68 125 160 27 75 75 45 215",
.DefaultCellBorder = New BorderInfo(BorderSide.None)
}
Dim row As Row = table.Rows.Add()
AddWorkaroundCell(row, String.Empty, BorderSide.Left Or BorderSide.Top Or BorderSide.Right)
AddWorkaroundCell(row, "1/2", BorderSide.All)
AddWorkaroundCell(row, String.Empty, BorderSide.Left Or BorderSide.Top Or BorderSide.Right)
AddWorkaroundCell(row, "1/4", BorderSide.Left Or BorderSide.Top Or BorderSide.Bottom)
AddWorkaroundCell(row, String.Empty, BorderSide.Top Or BorderSide.Bottom)
AddWorkaroundCell(row, String.Empty, BorderSide.Top Or BorderSide.Bottom)
AddWorkaroundCell(row, String.Empty, BorderSide.Top Or BorderSide.Bottom)
AddWorkaroundCell(row, String.Empty, BorderSide.Top Or BorderSide.Right Or BorderSide.Bottom)
row = table.Rows.Add()
AddWorkaroundCell(row, "1/1", BorderSide.Left Or BorderSide.Right)
AddWorkaroundCell(row, "2/1", BorderSide.Left Or BorderSide.Top Or BorderSide.Right)
AddWorkaroundCell(row, "1/3", BorderSide.Left Or BorderSide.Right)
AddWorkaroundCell(row, "2/2", BorderSide.All)
AddWorkaroundCell(row, "2/3", BorderSide.All)
AddWorkaroundCell(row, "2/4", BorderSide.All)
AddWorkaroundCell(row, "2/5", BorderSide.All)
AddWorkaroundCell(row, "2/6", BorderSide.Left Or BorderSide.Top Or BorderSide.Right)
row = table.Rows.Add()
AddWorkaroundCell(row, String.Empty, BorderSide.Left Or BorderSide.Right Or BorderSide.Bottom)
AddWorkaroundCell(row, String.Empty, BorderSide.Left Or BorderSide.Right Or BorderSide.Bottom)
AddWorkaroundCell(row, String.Empty, BorderSide.Left Or BorderSide.Right Or BorderSide.Bottom)
AddWorkaroundCell(row, "3/1", BorderSide.Left Or BorderSide.Top Or BorderSide.Bottom)
AddWorkaroundCell(row, String.Empty, BorderSide.Top Or BorderSide.Bottom)
AddWorkaroundCell(row, String.Empty, BorderSide.Top Or BorderSide.Bottom)
AddWorkaroundCell(row, String.Empty, BorderSide.Top Or BorderSide.Right Or BorderSide.Bottom)
AddWorkaroundCell(row, String.Empty, BorderSide.Left Or BorderSide.Right Or BorderSide.Bottom)
Return table
End Function
Private Function AddWorkaroundCell(row As Row, text As String, borderSide As BorderSide) As Cell
Dim cell As Cell = row.Cells.Add(text)
cell.Border = New BorderInfo(borderSide, 0.75F, Color.Red)
Return cell
End Function
table_rowspan_colspan_fixed_out.pdf (2.6 KB)
table_rowspan_colspan_original_out.pdf (2.1 KB)
i attached the results so you can check if that’s true on your side
If there’s still some issues remaining feel free to ask