ONLYOFFICE 文档 9.3 开发者版:PDF API、Office JavaScript API 新方法及更多功能


ONLYOFFICE 文档 9.3 为开发者带来了一系列更新。此版本显著增强了 API 功能,为编辑器的集成与扩展提供了更强的控制力与灵活性。我们来看看主要的更新内容。
全新 PDF API 简介
9.3 版本的重要新增功能之一是全新的 PDF API。这套工具集允许您通过编程方式创建和操作 PDF 文档。现在,您可以从头构建复杂的 PDF 文件,添加文本、图像、表格和形状等多种元素。
该 API 提供了对文档结构与内容的精细控制。您可以管理页面、处理富文本格式,并精确插入绘图及其他对象。这为自动化文档生成以及在应用中创建自定义的 PDF 解决方案开辟了更多可能。
查看创建新 PDF 文件的代码示例:
// create a PDF filewith ONLYOFFICE Document Builderbuilder.CreateFile("pdf")// create a new'oDocument'variableandget the created PDF documentconst oDocument = Api.GetDocument()// create a new paragraph for the PDF contentconst oParagraph = Api.CreateParagraph()// set the paragraph justification to center the textoParagraph.SetJc("center")// add a text containing a single 'Center' word to the paragraphoParagraph.AddText("Center")// push the paragraph to the documentoDocument.Push(oParagraph)// save the resulting PDF documentas a filein the .pdf formatwith the 'example.pdf'nameandclose itbuilder.SaveFile("pdf", "example.pdf")builder.CloseFile()
Office JavaScript API 重要更新
Office JavaScript API迎来了重要升级,在各个模块中新增了大量方法,以增强文档自动化与交互能力。
表单增强功能
我们新增了一系列用于处理表单的方法。现在,您可以通过编程方式管理表单字段,包括按钮、复选框、组合框和文本字段。这为动态创建和交互式表单提供了支持,使构建复杂的数据输入解决方案变得更加便捷。
绘图与注释功能扩展
绘图及注释相关的 API 得到了显著加强。新增的方法支持对形状、几何图形及其视觉属性(如填充和描边)进行更精细的控制。具体包括用于管理以下内容的新方法:
-
Annotations (caret, circle, highlight, ink, etc.)
-
Geometries and paths
-
Fills (gradients, colors) and strokes
以下为 ApiStroke/GetFill 方法(电子表格 API)的代码示例:
ApiStroke/GetFill:https://api.onlyoffice.com/zh-CN/docs/office-api/usage-api/spreadsheet-api/ApiStroke/Methods/GetFill/
// Creates a shape with a colored border and retrieves its fill properties.let worksheet = Api.GetActiveSheet();let fill = Api.CreateSolidFill(Api.CreateRGBColor(255, 200, 100));let stroke = Api.CreateStroke(2 * 36000, Api.CreateSolidFill(Api.CreateRGBColor(0, 0, 255)));let shape = worksheet.AddShape("rect", 60 * 36000, 40 * 36000, fill, stroke, 3, 0, 2, 2);let strokeObj = shape.GetLine();if (strokeObj) {let strokeFill = strokeObj.GetFill();if (strokeFill) { worksheet.GetRange("A1").SetValue("Stroke fill type: " + strokeFill.GetType()); }}
高级图表与表格方法
现在,对图表和表格的操作更加灵活。新增的 ApiChart 和 ApiTable 方法提供了对图表与表格创建及修改的更强大的程序化控制,使您能够构建内容更动态、数据更丰富的文档。
其他值得关注的 JavaScript API 新增功能
-
筛选与验证:新增了Autofilter、Filter及Validation相关方法,便于更好地管理电子表格中的数据。
-
脚注与尾注:支持通过编程方式在文档中添加和管理脚注及尾注。
-
超链接与切换效果:增强了对超链接以及演示文稿幻灯片切换效果的控制能力。
可查看新增方法的完整列表:https://api.onlyoffice.com/docs/office-api/more-information/changelog/#version-93
插件与宏 API 改进
在 9.3 版本中,插件和宏的 API 也迎来了重要更新。这些增强功能旨在为开发者提供更多扩展 ONLYOFFICE 编辑器功能的选项。现在,您可以创建功能更强大、集成度更高的插件,利用宏自动执行复杂的工作流程,并提供可根据特定用户需求定制的自定义功能。
例如,新增的 IsFormSigned 方法可用于检查指定表单是否已完成数字签名:
IsFormSigned :https://api.onlyoffice.com/docs/plugin-and-macros/interacting-with-editors/text-document-api/Methods/IsFormSigned/
window.Asc.plugin.executeMethod ("IsFormSigned", [], function(isSigned) { console.log ("Form is signed: " + isSigned);});
PDF 编辑器中新引入的宏 API 允许您添加、删除和编辑页面、表单、注释、自选图形、表格、图像和图表。例如,以下是 PDF API 的
window.Asc.plugin.executeMethod ("SetMacros", [JSON.stringify (Content)], function () { window.Asc.plugin.executeCommand ("close", "");});
查看插件和宏 API 的完整变更日志:https://api.onlyoffice.com/docs/plugin-and-macros/more-information/changelog/#version-93
立即获取 ONLYOFFICE 文档开发者版 9.3 版本
欢迎前往官方网站,下载 ONLYOFFICE 文档开发者版 9.3 ,体验所有全新功能:
立即下载

相关链接
API 文档:https://api.onlyoffice.com/zh-CN/
下载开发者版本:https://www.onlyoffice.com/zh/download-developer
PDF API:https://api.onlyoffice.com/zh-CN/docs/office-api/usage-api/pdf-api/
Office API 更新日志:https://api.onlyoffice.com/zh-CN/docs/office-api/more-information/changelog/

夜雨聆风
