Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migradoc Header with table

Tags:

c#

migradoc

I can make a header in Migradoc like this:

  //Create Header
  Paragraph paragraph = section.Headers.Primary.AddParagraph();
  paragraph.AddText("Roto");
  paragraph.Format.Font.Size = 9;
  paragraph.Format.Alignment = ParagraphAlignment.Center;

And I can make make a simple table like this:

  // Create the HEADER table for the top of every page
  this.table = section.AddTable();
  this.table.Style = "Table";
  this.table.Borders.Color = TableBorder;
  this.table.Borders.Width = 0.25;
  this.table.Borders.Left.Width = 0.5;
  this.table.Borders.Right.Width = 0.5;
  this.table.Rows.LeftIndent = 0;

  Column column = this.table.AddColumn("8cm");
  column.Format.Alignment = ParagraphAlignment.Center;

  column = this.table.AddColumn("8cm");
  column.Format.Alignment = ParagraphAlignment.Center;

  // Create the header of the table
  Row row = table.AddRow();
  //row = table.AddRow();
  row.HeadingFormat = true;
  row.Format.Alignment = ParagraphAlignment.Center;
  row.Format.Font.Bold = true;
  row.Shading.Color = TableBlue;

  row.Cells[0].AddParagraph("Rotary");
  row.Cells[0].MergeRight = 1;

  row = table.AddRow();
  row.HeadingFormat = true;
  row.Format.Alignment = ParagraphAlignment.Center;
  row.Format.Font.Bold = true;
  row.Shading.Color = TableBlue;
  row.Cells[0].AddParagraph("Part No.:");
  row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
  row.Cells[1].AddParagraph("Tested by:");
  row.Cells[1].Format.Alignment = ParagraphAlignment.Left;            

  row = table.AddRow();       
  row.Cells[0].MergeRight = 1;

How do I get the table into the header so it appears at the top of every page?

EDIT: So to make it work I changed:

this.table = section.AddTable();

to:

this.table = section.Headers.Primary.AddTable();
like image 713
Jeff Avatar asked Aug 05 '13 03:08

Jeff


1 Answers

If you want to have the same header on every page:
Use section.Headers.Primary.AddTable() instead of section.Headers.Primary.AddParagraph().

By setting row.HeadingFormat = true; for the first n rows of your table, you mark this rows as header rows. When the table grows and breaks over several pages, the header rows will be repeated on every page (but in the "normal" page body, not the header area). This is the typical usage of heading rows. If you don't add other rows to your header table, HeadingFormat = true will not have any effect.

like image 172
I liked the old Stack Overflow Avatar answered Oct 03 '22 06:10

I liked the old Stack Overflow