Different Headers / Same Footers

I am trying to create a document which contains two different headers. One for the first page and the second for remaining pages. I have got this to work just fine using the (HeaderFooterType.HeaderFirst) and the (HeaderFooterType.HeaderPrimary) directives. The problem i can’t seem to solve is haow to use one common footer which will appear on both the first page and subsequent pages.

I have tried defining the same footer configuration using the (HeaderFooterType.FooterFirst) and the (HeaderFooterType.FooterPrimary) directives, however when the actual primary footer is created it loses it’s alignment. But what is odd is that when Im looking at the Word Document that is created, and edit the header/footer area of the created document clicking the “Link to Previous” button of the header/footer editor toolbar, everything appears as it should and the alignment problem is resolved.

Could you please provide me with an example of how to solve this problem. I have reviewed the forums and the documentation but can’t seem to figure it out. Help

Hi

Thanks for your request. Could you please show me your code and attach your document here for testing. I will check the problem on my side and provide you more information.

Best regards,

I am attaching the code and the sample report. Notice the page number problem and the fotter alignment problem. Page numbering on first page should read “page1 of 12”

Hi ***,

Thank you for additional information. However, I cannot see any alignment issues with header on the first page and on the sequent pages. I attached screenshot.

Regarding the problem with number of pages value. It seems this is problem of MS Word. While opening the document MS Word automatically recalculate number of pages and for some reason in the first page Header/Footer it shows incorrect value. However, if you just open footer, MS Word recalculates the value again and displays the correct number.

Maybe, as a workaround, you can define first page Header/Footer as a Primary Header/Footer, but in separate section. For example see the following simple code:

// Create document.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// Insert Headers/Footers

builder.PageSetup.DifferentFirstPageHeaderFooter = false;

GenerateHeadersFooters(builder);

// Insert few pages

for (int i = 0; i < 10; i++)

builder.InsertBreak(BreakType.PageBreak);

// Save output document

doc.Save(@“Test001\out.doc”);

================================================================

private void GenerateHeadersFooters(DocumentBuilder builder)

{

// Insert Primary header of the first section.

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

builder.Font.Size = 24;

builder.Write(“This is Header, which will be displayed on the first page only.”);

// Insert primary footer of the first section.

builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

builder.Font.Size = 24;

builder.InsertField(“PAGE”, null);

builder.Write(" of ");

builder.InsertField(“NUMPAGES”, null);

// Move DocumentBuilder cursor at the beggining of the document and insert section break.

builder.MoveToDocumentStart();

builder.InsertBreak(BreakType.SectionBreakContinuous);

// Insert another primary header

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

builder.Font.Size = 24;

builder.Write(“This is another header”);

// Link footer to the previouse section.

builder.CurrentSection.HeadersFooters.LinkToPrevious(HeaderFooterType.FooterPrimary, true);

builder.MoveToDocumentEnd();

}

Hope this helps.

Best regards.

Thanks for your help. This fixed the problem