Methods

After initializing document editor you will get the object that can be used to call the methods.

  1. var docEditor = new DocsAPI.DocEditor("placeholder", config);

Methods and their description:

  • createConnector* - create the connector to interact with text documents, spreadsheets, presentations, and fillable forms from the outside.

    1. docEditor.createConnector();
  • denyEditingRights - deny editing. This method can be called when you want to make the document editing unavailable.

    1. docEditor.denyEditingRights(message);
    ParameterDescriptionTypePresence
    messageDefines the text messages for dialog.stringoptional
  • destroyEditor - destroy docEditor object. This method can be called when you want to reinit document editor with another configurations. Used since version 4.3.

    1. docEditor.destroyEditor();
  • downloadAs - download the edited file. This method can be called only when the existence of the onDownloadAs events. Document editing service asynchronously creates a document and triggers the onDownloadAs event with a link in parameter.

    1. docEditor.downloadAs(format);
    ParameterDescriptionTypePresence
    formatDefines the format in which a file will be downloaded. All the possible formats you can find in the conversion tables. But you cannot download a file in the image formats such as bmp, gif, jpg, png. If this parameter is undefined, the file will be downloaded in the OOXML format according to the file type.stringoptional

    Please note that conversion from the djvu, pdf, xps formats are not available. The original format will be downloaded.

  • insertImage - insert an image into the file. Starting from version 7.0, this method allows a user to insert several images. The images array is used to do it. This method must be called after the onRequestInsertImage events.

    1. docEditor.insertImage({
    2. "c": "add",
    3. "images": [
    4. {
    5. "fileType": "png",
    6. "url": "https://example.com/url-to-example-image1.png"
    7. },
    8. {
    9. "fileType": "png",
    10. "url": "https://example.com/url-to-example-image2.png"
    11. },
    12. ...
    13. ],
    14. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjIjoiYWRkIiwiaW1hZ2VzIjpbeyJmaWxlVHlwZSI6InBuZyIsInVybCI6Imh0dHBzOi8vZXhhbXBsZS5jb20vdXJsLXRvLWV4YW1wbGUtaW1hZ2UxLnBuZyJ9LHsiZmlsZVR5cGUiOiJwbmciLCJ1cmwiOiJodHRwczovL2V4YW1wbGUuY29tL3VybC10by1leGFtcGxlLWltYWdlMi5wbmcifV19.JfSa__qPeY3MjUgdkJDjdfJWBgvCmEdLfFzjd3WgeUA"
    15. });

    Where example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

    ParameterDescriptionTypePresence
    cDefines a type of image insertion from the event. Can be: add, change, fill, watermark, slide. The default value is “add“.stringrequired
    fileTypeDefines a type of the image to be inserted into the file. Can be: bmp, gif, jpe, jpeg, jpg, png. Deprecated since version 7.0, please use the images.fileType parameter instead.stringrequired
    imagesDefines an array of images to be inserted.array of objectsrequired
    images.fileTypeDefines a type of the image to be inserted into the file. Can be: bmp, gif, jpe, jpeg, jpg, png.stringrequired
    images.urlDefines an absolute URL where the source image is stored. Be sure to add a token when using local links.stringrequired
    tokenDefines the encrypted signature added to the parameter in the form of a token.stringoptional
    urlDefines an absolute URL where the source image is stored. Be sure to add a token when using local links. Otherwise, an error will occur. Deprecated since version 7.0, please use the images.url parameter instead.stringrequired

    Prior to version 7.0, this method allowed to insert only one image and had the following parameters:

    1. docEditor.insertImage({
    2. "c": "add",
    3. "fileType": "png",
    4. "url": "https://example.com/url-to-example-image.png"
    5. });

    Please note that this structure is deprecated and will not be supported by the next editors versions. Please use a new one.

  • refreshHistory - show the document version history. This method must be called after the onRequestHistory events.

    1. docEditor.refreshHistory({
    2. "currentVersion": 2,
    3. "history": [
    4. {
    5. "created": "2010-07-06 10:13 AM",
    6. "key": "af86C7e71Ca8",
    7. "user": {
    8. "id": "F89d8069ba2b",
    9. "name": "Kate Cage"
    10. },
    11. "version": 1
    12. },
    13. {
    14. "created": "2010-07-07 3:46 PM",
    15. "key": "Khirz6zTPdfd7",
    16. "user": {
    17. "id": "78e1e841",
    18. "name": "John Smith"
    19. },
    20. "version": 2
    21. },
    22. ...
    23. ],
    24. });

    If after editing and saving the document the history with the object changes and server version is returned, send the object changes in the changes parameter and the server version in the serverVersion parameter.

    1. docEditor.refreshHistory({
    2. "currentVersion": 2,
    3. "history": [
    4. {
    5. "changes": changes,
    6. "created": "2010-07-06 10:13 AM",
    7. "key": "af86C7e71Ca8",
    8. "serverVersion": serverVersion,
    9. "user": {
    10. "id": "F89d8069ba2b",
    11. "name": "Kate Cage"
    12. },
    13. "version": 1
    14. },
    15. {
    16. "changes": changes,
    17. "created": "2010-07-07 3:46 PM",
    18. "key": "Khirz6zTPdfd7",
    19. "serverVersion": serverVersion,
    20. "user": {
    21. "id": "78e1e841",
    22. "name": "John Smith"
    23. },
    24. "version": 2
    25. },
    26. ...
    27. ],
    28. });

    Where changes is the changes from the history object returned after saving the document.

    Where serverVersion is the serverVersion from the history object returned after saving the document.

    Show an error message explaining why the version history cannot be displayed:

    1. docEditor.refreshHistory({
    2. "error": "Exception",
    3. });
    ParameterDescriptionTypePresence
    currentVersionDefines the current document version number.integerrequired
    errorDefines the error message text.stringoptional
    historyDefines the array with the document versions.arrayrequired
    history.changesDefines the changes from the history object returned after saving the document.objectoptional
    history.createdDefines the document version creation date.stringrequired
    history.keyDefines the unique document identifier used by the service to recognize the document.stringrequired
    history.serverVersionDefines the current server version number. If the changes parameter is sent, then the serverVersion parameter is required to be sent as well.integeroptional
    history.userDefines the user who is the author of the document version.objectoptional
    history.user.idDefines the identifier of the user who is the author of the document version.stringoptional
    history.user.nameDefines the name of the user who is the author of the document version.stringoptional
    history.versionDefines the document version number.integerrequired
  • requestClose - request to close the editor. It is recommended to call this method before the destroyEditor method to check if there is some unsaved data in the editor or not. If the unsaved data exists, then the dialog box will be displayed to ask the user whether they want to continue editing or close the editor losing all the unsaved data. If the Close option will be chosen, then the onRequestClose event will be called.

    1. docEditor.requestClose();
  • setActionLink - set the link to the document which contains a bookmark. This method must be called after the onMakeActionLink event. The software integrator must process the ACTION_DATA received from the document editing service to set the link. The link is created by the software integrators who use ONLYOFFICE Document Server in their document manager.

    1. docEditor.setActionLink(link);
    ParameterDescriptionTypePresence
    linkDefines the link which allows scrolling to the bookmark position in the document.stringrequired
  • setFavorite - change the Favorite icon state. This method must be called after the onMetaChange event.

    1. docEditor.setFavorite(favorite);
    ParameterDescriptionTypePresence
    favoriteDefines if the Favorite icon is highlighted (true) or not (false).booleantrue
  • setHistoryData - send the link to the document for viewing the version history. This method must be called after the onRequestHistoryData events.

    1. docEditor.setHistoryData({
    2. "fileType": "docx",
    3. "key": "Khirz6zTPdfd7",
    4. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWxlVHlwZSI6ImRvY3giLCJrZXkiOiJLaGlyejZ6VFBkZmQ3IiwidXJsIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS91cmwtdG8tZXhhbXBsZS1kb2N1bWVudC5kb2N4IiwidmVyc2lvbiI6Mn0.iRcdHve235L5K1e29SmUBkuHcxb63WHRko51WMJlmS0",
    5. "url": "https://example.com/url-to-example-document.docx",
    6. "version": 2
    7. });

    Where example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

    If after editing and saving the document the changesurl link to the file with changes data is returned, download the file by this link and send the file URL in the changesUrl parameter. The absolute URL address of the document previous version must be sent in the previous.url parameter.

    1. docEditor.setHistoryData({
    2. "changesUrl": "https://example.com/url-to-changes.zip",
    3. "fileType": "docx",
    4. "key": "Khirz6zTPdfd7",
    5. "previous": {
    6. "fileType": "docx",
    7. "key": "af86C7e71Ca8",
    8. "url": "https://example.com/url-to-the-previous-version-of-the-document.docx"
    9. },
    10. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjaGFuZ2VzVXJsIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS91cmwtdG8tY2hhbmdlcy56aXAiLCJmaWxlVHlwZSI6ImRvY3giLCJrZXkiOiJLaGlyejZ6VFBkZmQ3IiwicHJldmlvdXMiOnsiZmlsZVR5cGUiOiJkb2N4Iiwia2V5IjoiYWY4NkM3ZTcxQ2E4IiwidXJsIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS91cmwtdG8tdGhlLXByZXZpb3VzLXZlcnNpb24tb2YtdGhlLWRvY3VtZW50LmRvY3gifSwidXJsIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS91cmwtdG8tZXhhbXBsZS1kb2N1bWVudC5kb2N4IiwidmVyc2lvbiI6Mn0.ril3Ol3rvYne3g0dG8TdKCiwJ7-7kkYGc6-XWMvp8FU",
    11. "url": "https://example.com/url-to-example-document.docx",
    12. "version": 2
    13. });

    Where example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

    Send an error message explaining why the document version cannot be displayed:

    1. docEditor.setHistoryData({
    2. "error": "Exception",
    3. "version": 2
    4. });
    ParameterDescriptionTypePresence
    changesUrlDefines the url address of the file with the document changes data, which can be downloaded by the changesurl link from the JSON object returned after saving the document. The request for file is signed with a token which is checked by the Document Server.stringoptional
    errorDefines the error message text.stringoptional
    fileTypeDefines an extension of the document specified with the url parameter.stringoptional
    keyDefines the document identifier used to unambiguously identify the document file.stringrequired
    previousDefines the object of the previous version of the document if changesUrl address was returned after saving the document.objectoptional
    previous.fileTypeDefines an extension of the document specified with the previous.url parameter.stringoptional
    previous.keyDefines the document identifier of the previous version of the document.stringrequired
    previous.urlDefines the url address of the previous version of the document.stringrequired
    tokenDefines the encrypted signature added to the parameter in the form of a token.stringoptional
    urlDefines the url address of the current document version. Can be downloaded by the url link from the JSON object returned after saving the document. Be sure to add a token when using local links. Otherwise, an error will occur.stringrequired
    versionDefines the document version number.integerrequired
  • setMailMergeRecipients - insert recipient data for mail merge into the file. This method must be called after the onRequestMailMergeRecipients events.

    1. docEditor.setMailMergeRecipients({
    2. "fileType": "xlsx",
    3. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWxlVHlwZSI6Inhsc3giLCJ1cmwiOiJodHRwczovL2V4YW1wbGUuY29tL3VybC10by1leGFtcGxlLXJlY2lwaWVudHMueGxzeCJ9.P3TjOyX1Tv3xAVRAc8qtNb-uFLD6FH_WErag_rbI6nQ",
    4. "url": "https://example.com/url-to-example-recipients.xlsx"
    5. });

    Where example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

    ParameterDescriptionTypePresence
    fileTypeDefines the type of spreadsheet for mail merge in the file. Can be: csv, fods, ods, ots, xls, xlsm, xlsx, xlt, xltm, xltx.stringrequired
    tokenDefines the encrypted signature added to the parameter in the form of a token.stringoptional
    urlDefines the absolute URL where the source data is stored. Be sure to add a token when using local links. Otherwise, an error will occur.stringrequired
  • setReferenceData - refresh data by a link to a file which is specified with the referenceData or path parameters. This method must be called after the onRequestReferenceData event.

    Please note that this method is executed only when the user has permissions to the file from which the data is taken.

    1. docEditor.setReferenceData({
    2. "fileType": "xlsx",
    3. "path": "sample.xlsx",
    4. "referenceData": {
    5. "fileKey": "BCFA2CED",
    6. "instanceId": "https://example.com"
    7. },
    8. "url": "https://example.com/url-to-example-document.xlsx"
    9. });

    Where the example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

    Show an error message explaining if any error occurred:

    1. docEditor.setReferenceData({
    2. "error": "Exception",
    3. });
    ParameterDescriptionTypePresence
    errorDefines the error message text.stringoptional
    fileTypeDefines an extension of the document specified with the url parameter.stringoptional
    pathDefines the file name or relative path for the formula editor. It is used to identify a file when the onRequestReferenceData event is executed.stringrequired
    referenceDataDefines an object that is generated by the integrator to uniquely identify a file in its system. This data must be the same as in the document.referenceData config parameter:
    • fileKey - the unique document identifier used by the service to get a link to the file. It must not be changed when the document is edited and saved (i.e. it is not equal to the document.key parameter),
      type: string,
      example: “BCFA2CED”;
    • instanceId - the unique system identifier. If the data was copied from a file on one system, and inserted into a file on another, then pasting by link will not be available and there will be no corresponding button in the context menu,
      type: string,
      example: “https://example.com“.
    objectoptional
    tokenDefines the encrypted signature added to the parameter in the form of a token.stringoptional
    urlDefines the URL address to download the current file.stringrequired
  • setRevisedFile* - select a document for comparing. This method must be called after the onRequestCompareFile events. * - available only for ONLYOFFICE Enterprise Edition and ONLYOFFICE Developer Edition

    1. docEditor.setRevisedFile({
    2. "fileType": "docx",
    3. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWxlVHlwZSI6ImRvY3giLCJ1cmwiOiJodHRwczovL2V4YW1wbGUuY29tL3VybC10by1leGFtcGxlLWRvY3VtZW50LmRvY3gifQ.t8660n_GmxJIppxcwkr_mUxmXYtE8cg-jF2cTLMtuk8",
    4. "url": "https://example.com/url-to-example-document.docx"
    5. });

    Where example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

    ParameterDescriptionTypePresence
    fileTypeDefines the type of document for comparing. Can be: doc, docm, docx, dot, dotm, dotx, epub, fodt, odt, ott, rtf, wps.stringrequired
    tokenDefines the encrypted signature added to the parameter in the form of a token.stringoptional
    urlDefines the absolute URL where the source document is stored. Be sure to add a token when using local links. Otherwise, an error will occur.stringrequired
  • setSharingSettings - update the information about the settings which allow to share the document with other users. This method can be called after the onRequestSharingSettings events.

    1. docEditor.setSharingSettings({
    2. "sharingSettings": [
    3. {
    4. "permissions": "Full Access",
    5. "user": "John Smith"
    6. },
    7. {
    8. "isLink": true,
    9. "permissions": "Read Only",
    10. "user": "External link"
    11. }
    12. ]
    13. });
    ParameterDescriptionTypePresence
    sharingSettingsDefines the settings which allow sharing the document with other users.array of objectoptional
    sharingSettings.permissionsDefines the access rights for the user with the name above.stringoptional
    sharingSettings.userDefines the name of the user with whom the document will be shared.stringoptional
  • setUsers - set a list of users to mention in the comments. This method must be called after the onRequestUsers events.

    1. docEditor.setUsers({
    2. "users": [
    3. {
    4. "email": "john@example.com",
    5. "name": "John Smith"
    6. },
    7. {
    8. "email": "kate@example.com",
    9. "name": "Kate Cage"
    10. },
    11. ...
    12. ]
    13. });

    Where example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

    ParameterDescriptionTypePresence
    usersDefines the list of the users.array of stringsoptional
    users.emailDefines the email address of the user.stringrequired
    users.nameDefines the full name of the user.stringrequired
  • showMessage - display a tooltip with a message. This method can be called only after the onAppReady events.

    1. docEditor.showMessage(message);
    ParameterDescriptionTypePresence
    messageDefines the message text.stringrequired

    Please note that displaying a tooltip with a message is not supported in the embedded platform type.

* - available for editing only for ONLYOFFICE Developer Edition