Search code examples
c#migradoc

Push paragraphs down to not overlap with page header in MigraDoc 1.5b3


The code below aims to add an image and date stamp to the page header and then populate the page with some text (for example one header and a couple of paragraphs).

The problem is that the text overlaps the page header, it starts at the same height as the date stamp paragraph in the page header. What am I doing wrong?

Section section = document.AddSection();
section.PageSetup.StartingNumber = 1;

Image image = section.Headers.Primary.AddImage(GetImageFromDB("LogoPageHeader")); // creates base64 encoded image string
image.LockAspectRatio = true;
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Left;
image.WrapFormat.Style = WrapStyle.TopBottom; // to push date stamp to below the bottom of the image

HeaderFooter header = section.Headers.Primary;
Paragraph paragraph = header.AddParagraph(DateTime.Now.ToString("MM/dd/yyyy"));
paragraph.Format.Alignment = ParagraphAlignment.Right;

Paragraph paragraph = document.LastSection.AddParagraph("Question Summary:", "Heading3");

paragraph = document.LastSection.AddParagraph();
paragraph.Format.Alignment = ParagraphAlignment.Left;
paragraph.AddText("Question: " + q.Text.Trim());

paragraph = document.LastSection.AddParagraph();
paragraph.Format.Alignment = ParagraphAlignment.Left;
paragraph.AddText("Answer: " + (String.IsNullOrEmpty(q.ReplyText.Trim()) ? q.ReplyCode.ToString() : q.ReplyText.Trim()));
paragraph.Format.SpaceAfter = "8pt";

The image is about 20x20mm.


Solution

  • You have to set the TopMargin of the PageSetup to reserve space for the header.

    See also:
    http://forum.pdfsharp.net/viewtopic.php?p=3077