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

Heading information in the header and footer
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2296
Page 1 of 1

Author:  natemobley [ Thu Jan 10, 2013 9:42 pm ]
Post subject:  Heading information in the header and footer

Is there a way to get the heading/title into the header and footer? And if the content for that heading/title carries over into a new page, that new page will need to display the same heading/title in the header and footer.

I have attached and image as an example. The footer in the example is not the first page under the "General Information" Section, but it would need to be on all the pages that the heading/title of "General Information" spills into.

Attachments:
footer.JPG
footer.JPG [ 9.92 KiB | Viewed 10254 times ]

Author:  MakroDoccer [ Fri Jan 11, 2013 6:30 am ]
Post subject:  Re: Heading information in the header and footer

This can be done via "Sections" in MigraDoc.

All you need is to start a new section for each chapter, whichs name shall appear in header/footer.

You always have to redefine your PageSetup (offsets/margins if they are not default).
But you can also specifiy specific text for header and footer for this section.

My code looks like this:

foreach(Chapter chpt in newPageChapterList)
{
Section section = doc.AddSection();
definePageSetup(section);
defineHeaderAndFooter(section, chpt.Title);
}

and within "defineHeaderAndFooter" (I did it for header, but you just have to do it for footer):

HeaderFooter header = section.Headers.Primary;
TextFrame tf = header.AddTextFrame();
... // layouting my headers textframe
Paragraph par = tf.AddParagraph(title);
... // layouting of the text

See my result below

Attachments:
example.png
example.png [ 10.07 KiB | Viewed 10249 times ]

Author:  natemobley [ Fri Jan 11, 2013 2:39 pm ]
Post subject:  Re: Heading information in the header and footer

If you start a new section, doesn't it start the page numbering over again. I am working on a legal document that needs continuous page numbering, but also needs the "section" number (of the legal document, not of the section number in relation to pdfsharp) in the header and footer.

Am I clear with my problem?

So the footer of the first page would have "Page 1, Section 1.1". If Section 1.1 carrries into page two, then the footer of page two would be "Page 2, Section 1.1". Then the footer of page three would be "Page 3, Section 1.2" if section 1.2 start on page two but did not finish or was the first thing on page three.

Author:  MakroDoccer [ Sat Jan 12, 2013 10:42 am ]
Post subject:  Re: Heading information in the header and footer

I am not clear, if understand your issue correctly.

Every Section automatically starts on a new page. So yes, if you have sub chapters (for which you don't start a new section), these won't be visible in section header/footer.
Resulting you have to differ between "new page chapters" and "sub chapters".
And - with my solution - then only the "new page chapter" titles are visible in header/footer.
For me this was no problem, because in my oppinion, it is more important for orientation to see the "top chapter" in header, than to see only the current active chapter.

Author:  Thomas Hoevel [ Mon Jan 14, 2013 10:09 am ]
Post subject:  Re: Heading information in the header and footer

natemobley wrote:
If you start a new section, doesn't it start the page numbering over again.
You can set the starting page number for each section. If you don't set it, you get what you expect (1, 2, 3, 4, 5, ...) as the new section continues the count of previous sections.

Author:  natemobley [ Mon Jan 14, 2013 2:21 pm ]
Post subject:  Re: Heading information in the header and footer

So Thomas can I retrieve the last used number from the previous section? If so then I can just make the next section start one number higher.

Author:  Thomas Hoevel [ Mon Jan 14, 2013 2:28 pm ]
Post subject:  Re: Heading information in the header and footer

natemobley wrote:
So Thomas can I retrieve the last used number from the previous section? If so then I can just make the next section start one number higher.
That's the default behavior (what you get when you don't do anything about page numbers).

Author:  natemobley [ Mon Jan 14, 2013 2:36 pm ]
Post subject:  Re: Heading information in the header and footer

Yes. Sorry. I just re-read your post and saw that. Thank you.

And thanks MakroDoccer. Your solution isn't exactly what I am looking for, but it does give me an idea of how to accomplish it.

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