We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Different headers on the first two pages

I am new to Aspose and we have and older version of Aspose Word (3.0.1.0). I have been tasked with creating a word document/report. The document is based on the currently used document and I cannot change much of it. So far, I have been able to reproduce this document and insert the correct data automatically. The one hurdle I cannot get passed concerns headers.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

The first page, basically a cover page, has no header and the second page has a unique header. All the remaining pages have a default header. I cannot use a template unless that is the only way around the problem, and even then I might not be able too, political reasons. The boss hates templates. The default header will contain data unique to the report.

Purchasing the newer version is a definite possibility. I did notice there are more options with the newer version. With this current version the HeaderFooterType.HeaderEven enum does not work. Primary and first work fine. I don’t think that wil help me, but I was wondering if this version has a known bug with the even header option.

If there is no way to have different headers on the first two pages, Can I merge two or more documetns into one?

Thanks

Hi

Thanks for your inquiry.

1. I use the latest version of Aspose.Words and HeaderEven works fine. See the code example.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.PageSetup.DifferentFirstPageHeaderFooter = true;

builder.PageSetup.OddAndEvenPagesHeaderFooter = true;

//Insert header of first page

builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);

builder.Write("This is Header First.");

//Insert header of even pages

builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);

builder.Write("This is Header Even.");

//Insert header of odd pages

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

builder.Write("This is Header Odd.");

//Insert three pages

builder.MoveToDocumentStart();

builder.InsertBreak(BreakType.PageBreak);

builder.InsertBreak(BreakType.PageBreak);

builder.InsertBreak(BreakType.PageBreak);

//Save document

doc.Save(@"290_109101_kgsDeveloper\out.doc");

2. I think that you can get diferent header s on first two pages using sections. For example see the following code.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.PageSetup.DifferentFirstPageHeaderFooter = true;

//Insert header of first page

builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);

builder.Write("This is Header First.");

//Insert primary header

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

builder.Write("This is Header of Second page");

//Move to document start

builder.MoveToDocumentStart();

builder.Write("this is first page");

//insert page break

builder.InsertBreak(BreakType.PageBreak);

builder.Write("this is second page");

//Insert section break

builder.InsertBreak(BreakType.SectionBreakNewPage);

//Unlink headers and footers

builder.CurrentSection.HeadersFooters.LinkToPrevious(false);

builder.PageSetup.DifferentFirstPageHeaderFooter = false;

//Insert primary header

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

builder.Write("This is Primary Header");

//Insert three pages

builder.MoveToDocumentEnd();

builder.Write("this is third page");

//Save document

doc.Save(@"290_109101_kgsDeveloper\out.doc");

3. You can merge documents using this method.

public void AppendDoc(Document dstDoc, Document srcDoc)

{

for (int i = 0; i < srcDoc.Sections.Count; i++)

{

//Import section

Section newSection = (Section)dstDoc.ImportNode(srcDoc.Sections[i], true, ImportFormatMode.KeepSourceFormatting);

//Insert section into destination document

dstDoc.Sections.Add(newSection);

}

}

I hope that this information will help you.

Best regards.