You try to write the table before you've added any content to the table. It is normal that nothing is shown on the page. Move writeSelectedRows()
down in your code:
PdfPTable table = new PdfPTable(9);
table.TotalWidth = 595;
// there isn't any content in the table: there's nothing to write yet
// Header row.
table.AddCell(GetCell("Header 1", 1, 2));
table.AddCell(GetCell("Header 2", 1, 2));
table.AddCell(GetCell("Header 3", 5, 1));
table.AddCell(GetCell("Header 4", 1, 2));
table.AddCell(GetCell("Header 5", 1, 2));
// Inner middle row.
table.AddCell(GetCell("H1"));
table.AddCell(GetCell("H2"));
table.AddCell(GetCell("H3"));
table.AddCell(GetCell("H4"));
table.AddCell(GetCell("H5"));
// Now we've added 2 rows: two rows will be shown:
table.WriteSelectedRows(0, -1, 300, 300, pcb);
Note that I've changed the number of columns in the table, because you're only adding 5 rows for the first row, and five rows for the second row. Note that incomplete rows aren't rendered, so that may be another reason why your code doesn't do what you expect.
Finally you should remove:
doc.Add(table);
This adds the table at the current position of the cursor in the page. That's probably not where you want it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…