I am trying to programmatically reproduce a header, and nothing I've tried will add a background color or shading. How do you format a table in a header?
HtmlFormatProvider provider = new HtmlFormatProvider();
RadFlowDocument html = provider.Import(sb.ToString());
Section section = html.Sections[0];
section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(24);
ThemableColor gray = new ThemableColor(new System.Windows.Media.Color {R = 220, G = 220, B = 220});
Header header = section.Headers.Add();
Table table = header.Blocks.AddTable();
TableRow row1 = table.Rows.AddTableRow();
TableCell Title = row1.Cells.AddTableCell();
TableCell Version = row1.Cells.AddTableCell();
Title.PreferredWidth = new TableWidthUnit(384);
Title.Shading.BackgroundColor = gray;
Title.Blocks.AddParagraph().Inlines.AddRun("Executive Summary");
Version.PreferredWidth = new TableWidthUnit(384);
Version.Shading.BackgroundColor = gray;
Version.Blocks.AddParagraph().Inlines.AddRun("Version Name:");
TableRow row2 = table.Rows.AddTableRow();
TableCell Incident = row2.Cells.AddTableCell();
TableCell Period = row2.Cells.AddTableCell();
Incident.Blocks.AddParagraph().Inlines.AddRun("Incident:");
Period.Blocks.AddParagraph().Inlines.AddRun("Period:");
PdfFormatProvider pdf = new PdfFormatProvider();
return pdf.Export(html);
The attached Header.png is an example of what I'm trying to reproduce.
Hello Darwin,
To achieve the desired results you must make the following changes/implementations:
ThemableColor gray = new ThemableColor(Color.FromRgb(220, 220, 220));
Border tableBorder = new Border(1,BorderStyle.Single, new ThemableColor(Colors.Black)); table.Borders = new TableBorders(tableBorder);
Paragraph versionParagraph = Version.Blocks.AddParagraph(); versionParagraph.Inlines.AddRun("Version Name:"); versionParagraph.TextAlignment = Alignment.Right;
Paragraph titleParagraph = Title.Blocks.AddParagraph(); Run titleRun = titleParagraph.Inlines.AddRun("Executive Summary"); titleRun.FontWeight = FontWeights.Bold; titleRun.FontSize = 20;
Result:
Here are also some articles you might find useful:
I hope this helps. Let me know if further assistance is required.
Regards,
Yoan
Yoah,
Worked perfectly. Thanks so much for a prompt and helpful answer!
Regards,
Darwin Pinder