跳到主要内容

GetText

获取页面上的所有文本内容。

备注

此功能仅在 ONLYOFFICE Docs 付费版本中可用。

语法​

expression.GetText();

expression - 表示 ApiPage 类的变量。

参数​

此方法没有任何参数。

返回值​

string

示例​

获取 PDF 中页面的所有文本内容。

// Useful for reading the text on a PDF page.

// Extract page text after adding a shape with text content in a PDF.

let doc = Api.GetDocument();
doc.AddPage(0);
let page = doc.GetPage(0);
let fill = Api.CreateSolidFill(Api.RGB(50, 150, 250));
let stroke = Api.CreateStroke(0, Api.CreateNoFill());
let shape = Api.CreateShape("rect", 150 * 36000, 80 * 36000, fill, stroke);
shape.SetPosition(10 * 12700, 10 * 12700);
let paragraph = shape.GetContent().GetElement(0);
paragraph.SetJc("left");
paragraph.AddText("Lorem selected text");
page.AddObject(shape);

console.log(`Page text is: ${page.GetText()}`);