PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Is section a page in Migradoc?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1842
Page 1 of 1

Author:  tulips [ Thu Nov 10, 2011 9:23 am ]
Post subject:  Is section a page in Migradoc?

Hello,

I am learning Migradoc but experimenting with fields as I cannot find any good documentation. So, is adding a section like adding a page in the document? Whenever I add a section it adds a new page but the footer pagenumber still says one? If I want to add a header and footer images on every page then how do I do it without avoiding first blank page?

Thanks!

-tulips

Author:  Thomas Hoevel [ Thu Nov 10, 2011 10:03 am ]
Post subject:  Re: Is section a page in Migradoc?

A section is a section - much like sections in Word. A section always starts on a new page. Every document needs at least one section.
The contents of the section will spread over as many pages as are needed.

You can add PageBreaks to that section to force a new page.

You can set Header and Footer for every section.

To add images, add them to "section.Footers.Primary".
To include the page number, add a paragraph and then call "paragraph.AddPageField()" for that paragraph.

With Headers and Footers you have FirstPage, EvenPage, and Primary.
EvenPage will be used when you set MirrorMargins in the PageSetup.
FirstPage will be used when you set DifferentFirstPageHeaderFooter in the PageSetup.
If neither of those is set, Primary is used for all pages in the section.

There won't be blank pages unless your code forces MigraDoc to create a blank page (e.g. by adding two sections if the first section remains empty).

Author:  tulips [ Thu Nov 10, 2011 10:26 am ]
Post subject:  Re: Is section a page in Migradoc?

Thank you Thomas! That helps me. Now, I understand new section starts on a new page!

Now, I found out LastSection used in your samples. If I define the section as LastSection in my document then it starts writing on the first page!
I guess I will keep only one section to keep it simple. I have question which is why does my text start on the header image? I need to explicitly say lots of
paragraph.AddLineBreak(); when I start writing text to my document. I would like to start writing after the header and not on the header? Where do I specify that for all the pages?

So, I have defined headers and footers like this:

static void DefineContent(Document document)
{
Section section = document.AddSection();
section.PageSetup.HeaderDistance = "0.2cm";
section.PageSetup.StartingNumber = 1;

HeaderFooter header = section.Headers.Primary;
MigraDoc.DocumentObjectModel.Shapes.Image image = header.AddImage("C:\\Users\\S\\Pictures\\S\\S.jpg");
image.Width = "19cm";
image.Height = "3cm";

// Create a paragraph with centered page number. See definition of style "Footer".
Paragraph paragraph = new Paragraph();
paragraph.AddTab();
paragraph.AddPageField();


// Add paragraph to footer
section.Footers.Primary.Add(paragraph);
}

Author:  Thomas Hoevel [ Thu Nov 10, 2011 12:56 pm ]
Post subject:  Re: Is section a page in Migradoc?

The value of section.PageSetup.TopMargin must be greater than 3 cm because that's the height of your header image. So 4 cm or 5 cm should do.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/