PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Apr 16, 2024 10:12 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Nov 10, 2011 9:23 am 
Offline

Joined: Tue Nov 08, 2011 12:24 pm
Posts: 22
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 10, 2011 10:03 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 10, 2011 10:26 am 
Offline

Joined: Tue Nov 08, 2011 12:24 pm
Posts: 22
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);
}


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 10, 2011 12:56 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 63 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group