PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Wed Dec 17, 2025 11:36 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: header-footer question
PostPosted: Sun Oct 28, 2012 11:54 am 
Offline

Joined: Sun Oct 28, 2012 11:27 am
Posts: 6
Hi, I'm new to migraDoc and very pleased with the results I am getting so far.

I am creating a catalogue of concerts and want to have headers and footers like this:

- the headers should be different for the first and the other pages
(It should be empty at the start of a section and show the current artist's name otherwise)
- the footers should always have the page numbers, but on the left for odd and on the right side for even pages.

I can get one of the two to work, but not both.

here is a snippet, which will do it almost right:

Code:
                currentSection = document.AddSection();
                currentSection.PageSetup.DifferentFirstPageHeaderFooter = true;
                currentSection.PageSetup.OddAndEvenPagesHeaderFooter = true;
                currentSection.PageSetup.MirrorMargins = true;

                Paragraph footer = currentSection.Footers.Primary.AddParagraph();
                Paragraph footerE = currentSection.Footers.EvenPage.AddParagraph();
                Paragraph footerF = currentSection.Footers.FirstPage.AddParagraph();
                footer.AddPageField();
                footerE.AddPageField(); footerE.Format.Alignment = ParagraphAlignment.Right;
                footerF.AddPageField();

                //if (???page is even???) footerF.Format.Alignment = ParagraphAlignment.Right;

                Paragraph headerG = currentSection.Headers.FirstPage.AddParagraph();
                headerG.Add(writeFText(genre + "   ", 9, ""));
                Paragraph header = currentSection.Headers.Primary.AddParagraph();
                header.Add(writeFText(genre + "   ", 9, ""));
                header.Add(writeFText("     " + artist,10, "B"));


however the footerF will always be aligned left.
managing the left(right changes by hand does not seem right, as this is the renderer's job right?
and leaving out the FooterF completely will not have a page number on each section's first page.

Thanks in advance for any hints!

Thomas Wulf


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 29, 2012 9:50 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3139
Location: Cologne, Germany
Hi, Thomas,

A clean solution would be having each section (each artist) begin on e.g. an even page; the first page footer will then be correct, but there will be empty pages for artists that fill an odd number of pages.

You can create a new MigraDoc document for each section (each artist) and combine them (similar to the Mix MigraDoc and PDFsharp sample).

Or create a new MigraDoc document for each section (each artist) and render them just to calculate the page count for each artist, and finally create a huge MigraDoc document with all artists, settings first page footers based on the page counts you calculated earlier.
I'm not sure but I presume that generating a single, huge MigraDoc document might result in smaller PDF files than combining many small files.

In our documents we normally use the first approach, having some empty pages between sections. This will be acceptable if artists typically have 15 through 30 pages but may look odd if artists typically have 1 through 3 pages.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 29, 2012 10:23 am 
Offline

Joined: Sun Oct 28, 2012 11:27 am
Posts: 6
Hi Thomas,

Thanks for your reply.

Unfortunately many artists fill only one or two pages, so, as I try to minimize the total page count, leaving blank pages is not acceptable.

I guess I will have to redefine the header to appear also on the 1st page. Not a big issue, but hey, doesn't that sound like an enhancement request:

    - either control the 1st page-option for footers and header separately
    - or maybe create a mirror alignment-option for them, also separately, of course.

Chrismas is racing towards us, for why not wish for both ;-)

thanks, Thomas


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 293 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