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

Free Support Forum - aspose.com

How to check document has blank header text using aspose.words?

how to check document has header text or not.By using this given below code it is entering even when doucment has no header text…i mean if document has blank header without text…it is becoming not null…

if (para.GetAncestor(NodeType.HeaderFooter) != null)

Hi,

Please use the following code snippet to to find that either Header has text or not.

Document doc = new Document(MyDir + "doc1.docx");
HeaderFooter primaryHeader = doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary];
if (primaryHeader == null || primaryHeader.ToTxt().Trim() == "")
{
    //No Text
}

i tried the following code but iam getting space for start page?actually if document doesnt contains header i gave header distance as 0.8…it is working for remaining pages not for starting page y iam not getting?

oDocBuilder = new Aspose.Words.DocumentBuilder(oDocument);
Aspose.Words.PageSetup oPageSetup = oDocBuilder.PageSetup;
oPageSetup.TopMargin = ConvertUtil.InchToPoint(0.5);
oPageSetup.BottomMargin = ConvertUtil.InchToPoint(0.5);
oPageSetup.LeftMargin = ConvertUtil.InchToPoint(0.5);
oPageSetup.RightMargin = ConvertUtil.InchToPoint(0.5);
HeaderFooter primaryHeader = oDocument.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary];
if (primaryHeader == null || primaryHeader.ToTxt().Trim() == "")
{
    //No Text
    oPageSetup.HeaderDistance = ConvertUtil.InchToPoint(0.8);
    oPageSetup.FooterDistance = ConvertUtil.InchToPoint(0.8);
}
else
{
    oPageSetup.HeaderDistance = ConvertUtil.InchToPoint(1.0);
    oPageSetup.FooterDistance = ConvertUtil.InchToPoint(1.0);
}

Hi,

Please share your document for investigation purposes.