Hi
At first, let me congratulate you to MigraDoc + SharpPDF, two great products. I started using them yesterday and have come quite far already. Sometimes it requires a Change in thinking but I haven't come across a real Problem yet (except this one
).
I try to draw a table with 8 columns where each cell only contains some numbers. Therefore I'd like to write the headers rotated by 90°. I got this working, but there is an unusual large space after the text and I do not know where this comes from. I made a Picture of the resulting PDF so you can see what I mean.
The code Looks like this:
Code:
Table t = InitializeTable(doc, s, 8, Unit.FromMillimeter(15));
t.AddHeaderRowToTable(descs, colors);
Where the second function is an Extension method to the MigraDoc "Table".
Code:
private static Table InitializeTable(Document doc, Section s, int nrColumns, Unit colWidth)
{
Table t = s.AddTable();
t.Borders = new Borders {Visible = true, Width = 0.1};
for (int i = 0; i < nrColumns; i++)
{
t.AddColumn(colWidth);
}
double leftIndentForTable = (doc.DefaultPageSetup.PageWidth.Millimeter - doc.DefaultPageSetup.LeftMargin.Millimeter - doc.DefaultPageSetup.RightMargin.Millimeter - (t.Columns.Count * t.Columns[0].Width.Millimeter)) / 2;
t.Rows.LeftIndent = Unit.FromMillimeter(leftIndentForTable);
return t;
}
public static void AddHeaderRowToTable(this Table t, List<string> descriptions, List<Color> backgroundColors)
{
Row rFirst = t.AddRow();
//rFirst.HeadingFormat = true;
for (int i = 0; i < descriptions.Count; i++)
{
TextFrame tr = rFirst.Cells[i].AddTextFrame();
rFirst.Cells[i].Shading.Color = backgroundColors[i];
rFirst.Cells[i].Shading.Visible = true;
rFirst.Cells[i].Format.Alignment = ParagraphAlignment.Center;
tr.Orientation = TextOrientation.Upward;
tr.AddParagraph(descriptions[i]);
}
}
Do you have any idea what I am doing wrong? Why is there so much space above the table Header?
btw: Embedding Graphs made by OxyPlot works very nicely.