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

header-footer question
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2184
Page 1 of 1

Author:  tawulf [ Sun Oct 28, 2012 11:54 am ]
Post subject:  header-footer question

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

Author:  Thomas Hoevel [ Mon Oct 29, 2012 9:50 am ]
Post subject:  Re: header-footer question

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.

Author:  tawulf [ Mon Oct 29, 2012 10:23 am ]
Post subject:  Re: header-footer question

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

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