跳到主要内容

SetTextAlign

设置控件文本对齐方式。

备注

仅适用于文本/组合框/列表框字段控件。

继承自 ApiBaseWidget.SetTextAlign。

语法​

expression.SetTextAlign(textAlign);

expression - 表示 ApiButtonWidget 类的变量。

参数​

名称必需/可选数据类型默认值描述
textAlign必需WidgetTextAlign文本对齐方式。

返回值​

boolean

示例​

在 PDF 中设置字段控件的文本对齐方式。

// How do I align text in form field widgets in a PDF?

// Center the text displayed in all widgets of a form field in a PDF.

let doc = Api.GetDocument();
let page = doc.GetPage(0);
let textField = Api.CreateTextField([10, 10, 160, 30]);
page.AddObject(textField);

textField.SetValue('Example text');
textField.AddWidget(0, [10, 40, 160, 60]);
let widgets = textField.GetAllWidgets();
widgets.forEach(function(widget) {
widget.SetTextAlign('center');
});