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.
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:DoNotShowRevisions/>
<w:DoNotPrintRevisions/>
<w:DoNotShowMarkup/>
<w:DoNotShowComments/>
<w:DoNotShowInsertionsAndDeletions/>
<w:DoNotShowPropertyChanges/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-GB</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>TH</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:ApplyBreakingRules/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; mso-bidi-font-size:14.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Cordia New"; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

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.