I’m trying to get the headerFooter settings of a section. The problem I face is that when a headerFooter is linked to the one of the previous section, it is null when I try to get it. Instead, I should retrieve an headerFooter element with its IsLinkedToPrevious proerty set to null. This is not the case.
For example, if you try to get the first page footer of the second section of the attached document, you’ll have a null reference instead:
Thank you for reporting this problem to us. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed.
Best regards,
Thanks for your inquiry. Yes, I think your code should work this problem around.
Please let me know in case of any issues. I will be glad to help you.
Best regards,
It seems to me the bug you have is more general. Looks like Aspose.Words returns null every time a header or a footer doesn’t have content.
In the attached document, this is problematic to us since we are not able to determine that the document has both a primary header and an empty first header.
Here is the code to reproduce this problem ?
Document document = new Document(@"header test.doc");
HeaderFooterCollection headersFooters = document.FirstSection.HeadersFooters;
foreach (HeaderFooter headerFooter in headersFooters)
{
Console.WriteLine(headerFooter.HeaderFooterType);
}
Until you provide a fix, do you have a workaround?
Hi David,
Thanks for your request. This is expected that the section does not contain HeaderFooter nodes of all types. Ms Word simply does not write HeaderFooter if it is empty in this case Aspose.Words returns null for this type of HeaderFooter. As a workaround, you can simply check whether the section contain HeaderFooter nodes of each type: https://reference.aspose.com/words/net/aspose.words/headerfootertype/
Best regards,
In the case a document as both a primary section and an empty first section, how can I determine this programmatically ? If I do a check of a section which has a primary header, I cannot know if the section doesn’t have a first header (i.e. all the pages will have the primary header) or has an empty first header (i.e. all the pages will have the primary header except the first page).
Hi
Thanks for your request. I suppose, you can use code like the following to check each type of HeaderFooter in each section:
// Open document.
Document doc = new Document("in.doc");
// Loop through section in the document.
foreach(Section sect in doc.Sections)
{
// Process HeaderFooter nodes in order you need.
if (sect.HeadersFooters[HeaderFooterType.HeaderFirst] != null)
{
// Process first page header.
}
if (sect.HeadersFooters[HeaderFooterType.HeaderEven] != null)
{
// Process even page header.
}
if (sect.HeadersFooters[HeaderFooterType.HeaderPrimary] != null)
{
// Process primary page header.
}
if (sect.HeadersFooters[HeaderFooterType.FooterFirst] != null)
{
// Process first page footer.
}
if (sect.HeadersFooters[HeaderFooterType.FooterEven] != null)
{
// Process even page footer.
}
if (sect.HeadersFooters[HeaderFooterType.FooterPrimary] != null)
{
// Process primary page footer.
}
}