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.