ONLYOFFICE Docs 8.0 for developers: API and Doc Builder updates
Along with the release of the new features in version 8.0, we updated API for the editors, Document Builder, and plugins. Check all the details below.
PDF support
We added the pdf document type to the documentType parameter. This means that PDF files*, including those containing fillable fields, are now fully supported and can be opened for annotating and filling in ONLYOFFICE PDF Editor (earlier such files were recognized as documents and opened in the document editor).
var docEditor = new DocsAPI.DocEditor("placeholder", {
"documentType": "pdf",
*Also DjVu, OXPS and XPS
API for working with forms
The formsdataurl parameter added to the Callback handler allows defining the URL to the JSON file with the submitted form data. This file contains the following parameters:
- key
- tag
- value
- type (text, checkBox, picture, comboBox, dropDownList, dateTime, radio)
Moreover, you will find new form methods in the DocBuilder API:
- ApiDocument/GetFormsData which returns the data from all forms present in the current document;
- ApiDocument/SetFormsData which sets the data to the specified forms.
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph1 = oDocument.GetElement(0);
var oCheckBox = Api.CreateCheckBoxForm({"key": "BestCompany"});
oParagraph1.Push(oCheckBox);
var oTextForm = Api.CreateTextForm({"key": "CompanyName"});
oParagraph1.Push(oTextForm);
oDocument.SetFormsData([
{"key": "BestCompany", "value": true},
{"key": "CompanyName", "value": "ONLYOFFICE"}
]);
builder.SaveFile("docx", "SetFormsData.docx");
builder.CloseFile();
Enhanced WOPI support
The latest release brings the WOPISrc query parameter which is added to the requests from the browser to the server. This allows you to create several independent instances of ONLYOFFICE. Load balancing requests with WOPISrc
ensure that collaborative editing works correctly: all users editing the same document are served by the same server.
For WOPI, the parameter sent by the integrator is used. For the Docs API, the document.key parameter is written to WOPISrc
.
Conversion API
The watermark field added to the conversion request defines a JSON object containing the properties of a watermark which is inserted into the PDF and image files during conversion.
"async": false,
"filetype": "docx",
"key": "Khirz6zTPdfd7",
"outputtype": "pdf",
"title": "Example Document Title.docx",
"url": "https://example.com/url-to-example-document.docx",
"watermark": {
"align": 1,
"fill": [255, 0, 0],
"height": 100,
"margins": [ 10, 10, 10, 10 ],
...
Support for Oracle and Microsoft SQL Server databases
Among the supported databases there are now also Oracle and Microsoft SQL Server. To connect it, change the database type to oracle / mssql
. For Docker, you will need to adjust the DB_TYPE parameter.
Besides, you can use:
- Advanced connection settings for oracle –
oracleExtraOptions
- Advanced connection settings for mssql –
msSqlExtraOptions
User avatars
Starting from version 8.0, it’s possible to add user avatars to be displayed in the editors for better team visualization.
Thus, the info
operation type is added to the setUsers method and onRequestUsers event to set the avatars for the users with the IDs specified in the data.id
parameter. And the newly added users.image
field defines the path to the user avatar.
var onRequestUsers = function (event) {
var c = event.data.c;
var id = event.data.id;
...
docEditor.setUsers({
"c": event.data.c,
"users": [
{
"email": "john@example.com",
"id": "78e1e841",
"image": "https://example.com/url-to-user-avatar1.png",
"name": "John Smith"
},
Besides, the editorConfig.user parameter now contains the image field to define the path to the user avatar:
var docEditor = new DocsAPI.DocEditor("placeholder", {
"editorConfig": {
...
"user": {
"group": "Group1",
"id": "78e1e841",
"image": "https://example.com/url-to-user-avatar.png",
"name": "John Smith"
}
More API updates for the editors
- The editorConfig.customization.mobileForceView parameter to define if the mobile document editor is opened in the view/edit mode on launch. The default value is true.
- The link field in the data object which is sent to the events.onRequestReferenceData event.
Get the latest version of ONLYOFFICE Docs Developer:
API enhancements for plugins
The newly added plugin methods allow launching and managing slideshows:
- EndSlideShow
- GoToNextSlideInSlideShow
- GoToPreviousSlideInSlideShow
- GoToSlideInSlideShow
- PauseSlideShow
- ResumeSlideShow
- StartSlideShow
Find below several code samples:
window.Asc.plugin.executeMethod ("StartSlideShow");
window.Asc.plugin.executeMethod ("GoToSlideInSlideShow", [2]);
window.Asc.plugin.executeMethod ("EndSlideShow");
Further API updates for Document Builder
In the DocBuilder API, we also added multiple freeze panes and comment methods, and some others, including the following ones:
- ApiFreezePanes/GetLocation which returns a range that describes the frozen cells in the active worksheet view.
- ApiBlockLvlSdt/AddComment which adds a comment to the current block content control.
- ApiSection/GetPageHeight which gets page height for current section.
- ApiDocument/AddDrawingToPage which adds a shape to the specified page.
Check the full list of new methods.
Create your free ONLYOFFICE account
View, edit and collaborate on docs, sheets, slides, forms, and PDF files online.