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

Free Support Forum - aspose.com

Setting different headers/footers for the first page

Here is a problem reported by one of our users:

We are creating our reports with Aspose Words.
Before we buy a license we want to ensure all functionalities are covered.
Till now everything was going on well, except following points:

  1. Cannot set the header and/or footer of the first page only (not for all pages !!). If I set the header with “Aspose.Words.HeaderFooterType.HeaderFirst”, then the header is never shown. If I set the header with “Aspose.Words.HeaderFooterType.HeaderPrimary”, then it is shown in all pages, which is not desired.
  2. The header and footer show 2 lines crossing them, which is not desired in our reports.

And here is the answer.

Concerning defining different headers/footers for the first page. First you need to create a header/footer of HeaderFooterType.HeaderFirst/HeaderFooterType.FooterFirst type, fill it with data, and add it to section’s HeadersFooters collection. I can see that you have already done this. Then you need to enable showing different headers/footers for the foirst page in your document. That is controlled by PageSetup.DifferentFirstPageHeaderFooter property, which needs to be set to true. This property actually corresponds to File |Page Setup | Layout| Different first page setting in MS Word 2003.

Generally, there is a good example of header/footer creation that I have written some time ago. Here is a link to it:
https://docs.aspose.com/words/net/working-with-headers-and-footers/

There is also a similar article in offline documentation in Code Examples section.

I would also recommend you to use templates premade in MS Word for document generation. Everything that is common to generated documents should be put there. That is preferrable to creating documents from scratch using DocumentBuilder, because it is much more convenient to design templates visually in MS Word then create them from code.

As for the two lines in headers/footers - I really don’t have enough information to understand why are they present there and how you can get rid of them. You need to provide more info, and probably attach you document templates and generated document samples and also code that you use for document generation so that I could give you some meaningful recommendation.

Best regards

For the sake of those who wants to know how to do, here’s the new link to the documentation page :
https://docs.aspose.com/words/net/working-with-headers-and-footers/

For the sake of those who want to know how to do, here’s the new link to the documentation page :
https://docs.aspose.com/words/net/working-with-headers-and-footers/

Hello Anouck,

Thank you for sharing this information. Please let us know in case of any issues. We will be glad to help you.

Best regards,