SetWidowControl
Specify whether a single line of this paragraph will be prevented from being displayed on a separate page from the remaining content at display time by moving the line onto the following page.
Parameters:
Name |
Type |
Description |
isWidowControl |
boolean
|
The true value will enable the SetWidowControl method use. |
Returns:
-
This method doesn't return any data.
Example
Copy code
builder.CreateFile("docx");
oDocument = Api.GetDocument();
oMyStyle = oDocument.CreateStyle("My document style");
oParaPr = oMyStyle.GetParaPr();
oParaPr.SetWidowControl(true);
oParagraph = oDocument.GetElement(0);
oParagraph.AddText("The single line of the last paragraph on this page will be prevented from being displayed on a separate page. ");
for (x = 0; x < 5; ++x) {
oParagraph = Api.CreateParagraph();
for (i = 0; i < 10; ++i) {
oParagraph.AddText("These sentences are used to add lines for demonstrative purposes. ");
}
oDocument.Push(oParagraph);
}
oParagraph = Api.CreateParagraph();
for (i = 0; i < 3; ++i) {
oParagraph.AddText("These sentences are used to add lines for demonstrative purposes. ");
}
oParagraph.SetStyle(oMyStyle);
oParagraph.AddText("This last line would be displayed on the next page, if we had not used the set widow control method.");
oDocument.Push(oParagraph);
builder.SaveFile("docx", "SetWidowControl.docx");
builder.CloseFile();
Resulting document