<< Click to Display Table of Contents >> Navigation: Programming > Create text under program control > Header/Footer API > HeaderFooter.Get() API |
We suggest to use this code to add a new header:
WPRichText1.HeaderFooter.Get(
wpIsHeader,
wpraOnAllPages,
'').RtfText.AsString
:= WPEditor.AsString; // any other TWPRichText which is used to edit the header
-or-
WPRichText1.HeaderFooter.Get(
wpIsHeader,
wpraOnAllPages, '').RtfText.LoadFromStream( filestream1 );
C++Builder:
WPRichText1->HeaderFooter->Get(wpIsHeader,wpraOnAllPages,"")->RtfText->AsString;
Example: Create a Footer with the text "PAGE # of ##"
var par : TParagraph;
txtplain : Cardinal;
begin
par:=WPRichText1.HeaderFooter.Get(wpFooter,wpraOnAllPages).FirstPar;
WPRichText1.WritingAttr.Clear;
WPRichText1.WritingAttr.SetFontName('Courier New');
WPRichText1.WritingAttr.SetFontSize(900); // 9pt
txtplain := WPRichText1.WritingAttr.CharAttr;
par.ClearText;
par.ASet(WPAT_Alignment, Integer(paralRight));
par.Insert(0,'Page ',txtplain);
par.InsertNewObject(maxint, wpobjTextObject, false, false,txtplain).Name := WPTextFieldNames[wpoPageNumber];
par.Insert(maxint,' of ',txtplain);
par.InsertNewObject(maxint, wpobjTextObject, false, false,txtplain).Name := WPTextFieldNames[wpoNumPages];
end;
Please note that the property 'FirstPar' will always create a paragraph if the text block was empty.
Since WPTools 9 you can also use this code:
par.SetProperty(WPAT_Alignment,Integer(paralRight))
.Append('Page ',txtplain)
.Append(wpoPageNumber,txtplain)
.Append(' of ',txtplain)
.Append(wpoNumPages,txtplain);