跳到主要内容

SetKeepLines

指定在使用页面视图呈现文档时,尽可能将当前段落的所有行保持在同一页上。

继承自 ApiParaPr.SetKeepLines。

语法​

expression.SetKeepLines(isKeepLines);

expression - 表示 ApiParagraph 类的变量。

参数​

名称必需/可选数据类型默认值描述
isKeepLines必需booleantrue 值启用将段落各行保持在同一页上的选项。

返回值​

boolean

示例​

在文档中防止段落被拆分到两页。

// How do I keep all lines of a paragraph together on the same page in a document?

// Force a paragraph to stay on one page instead of breaking across pages in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("This is an example of how the paragraph tries to keep lines together. ");
paragraph.AddText("Scroll down to the second page to see it.");
for (let x = 0; x < 5; ++x) {
paragraph = Api.CreateParagraph();
for (let i = 0; i < 10; ++i) {
paragraph.AddText("These sentences are used to add lines for demonstrative purposes. ");
}
doc.Push(paragraph);
}
paragraph = Api.CreateParagraph();
paragraph.AddText("The paragraph lines are moved to the next page to keep them together. ");
for (let i = 0; i < 10; ++i) {
paragraph.AddText("These sentences are used to add lines for demonstrative purposes. ");
}
paragraph.SetKeepLines(true);
doc.Push(paragraph);