0

I'm working on a pdf that is generated using migradoc. However the Header and main section are overlapping when a row in the header expands due to a larger address than 3 or 4 lines.

I have used the answer on MigraDoc table goes over header on page 2? but the top margins will not move at all.

Where am I going wrong?

Section section = doc.AddSection();
section.PageSetup.TopMargin = Unit.FromCentimeter(4);

MigraDoc.DocumentObjectModel.Tables.Table quoteTable = section.Headers.Primary.AddTable();
quoteTable.Style = "Table";
quoteTable.Borders.Color = Colors.Black;
quoteTable.Borders.Width = 0.25;
quoteTable.Borders.Left.Width = 0.5;
quoteTable.Borders.Right.Width = 0.5;
quoteTable.Rows.LeftIndent = 0;
quoteTable.TopPadding = 3;
quoteTable.BottomPadding = 3;

quoteRow = quoteTable.AddRow();
quoteRow.HeadingFormat = true;
quoteRow.Format.Alignment = ParagraphAlignment.Center;
quoteRow.Format.Font.Bold = true;
quoteRow.Shading.Color = Colors.White;
quoteRow.Cells[0].AddParagraph("Customer Name");
quoteRow.Cells[0].MergeDown = 2;
quoteRow.Cells[0].Format.Alignment = ParagraphAlignment.Left;
quoteRow.Cells[0].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Top;
quoteRow.Cells[0].Format.Font.Bold = true;
quoteRow.Cells[0].Shading.Color = headingColour;
quoteRow.Cells[1].AddParagraph(contactName + Environment.NewLine + completeAddressDetails);
quoteRow.Cells[1].MergeDown = 2;
quoteRow.Cells[1].Format.Alignment = ParagraphAlignment.Left;
quoteRow.Cells[1].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Top;

MigraDoc.DocumentObjectModel.Tables.Table prodTable = section.AddTable();
prodTable.Style = "Table";
prodTable.Borders.Color = Colors.Black;
prodTable.Borders.Width = 0.25;
prodTable.Borders.Left.Width = 0.5;
prodTable.Borders.Right.Width = 0.5;

MigraDoc.DocumentObjectModel.Tables.Row row = prodTable.AddRow();
row.Format.Alignment = ParagraphAlignment.Center;
row.Format.Font.Bold = true;
row.Shading.Color = Colors.LightGray;
row.BottomPadding = 3;
row.TopPadding = 3;
row.Cells[0].AddParagraph("Manufacturer Product Code");
row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
row.Cells[0].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Bottom;
row.Cells[1].AddParagraph("Product Description");
row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
row.Cells[1].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Bottom;
row.Cells[2].AddParagraph("Qty" + Environment.NewLine + " Required");
row.Cells[2].Format.Alignment = ParagraphAlignment.Right;
row.Cells[2].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Bottom;
Peter Csala
  • 17,736
  • 16
  • 35
  • 75
Melissa
  • 11
  • 4
  • Code snippets often are not helpful. Maybe provide the complete MDDDL for a document with overlapping contents. http://pdfsharp.net/wiki/MigraDocDDL.ashx – I liked the old Stack Overflow Jun 16 '21 at 18:30
  • The file is too big to comment so I've uploaded it here: https://drive.google.com/file/d/1HQaDWBirGruJUn5OzYJAWY5wgPn00Ag5/view?usp=sharing – Melissa Jun 17 '21 at 08:09
  • I ended up using section.PageSetup.HeaderDistance = Unit.FromCentimeter(.5); instead of section.PageSetup.TopMargin This isn't as neat as TopMargin, but stops the overlap from occurring. – Melissa Jun 21 '21 at 07:55

0 Answers0