Background Color or Shading in Header?

0 Answers 70 Views
PdfProcessing
Darwin
Top achievements
Rank 1
Darwin asked on 22 Oct 2024, 10:48 PM

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.

Yoan
Telerik team
commented on 23 Oct 2024, 02:15 PM

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

 

Darwin
Top achievements
Rank 1
commented on 23 Oct 2024, 08:36 PM

Yoah,

Worked perfectly.  Thanks so much for a prompt and helpful answer!

Regards,

Darwin Pinder

No answers yet. Maybe you can help?

Tags
PdfProcessing
Asked by
Darwin
Top achievements
Rank 1
Share this question
or