ONLYOFFICE Docs API Samples: A Resizable Editor Dialog and Live Watermark Updates
If you build on top of ONLYOFFICE Docs, these two samples show how to embed the editor in a modal and drive its watermark from your own UI.

If you build on top of ONLYOFFICE Docs, two new samples from the API changelog 10.3.0 cover common integration requests: opening the editor without leaving the current page, and changing the watermark from your own interface.
- A native
<dialog>that hosts the editor and can be moved, resized and closed. - The editor's own cross button wired to your dialog.
- A watermark set in the config and replaced at runtime through the Automation API.
Let's dig in.
What the Samples Do
Opening the editor in a dialog opens the editor over the page. Users move the dialog by the top edge of the frame, resize it by the other edges and corners, and close it with the cross button in the editor.
Working with watermark changes the watermark drawn over the pages from an external UI, for example to show the current user's name or the document status. The editor redraws the pages in real time.
How It Works
The Dialog and Its Frame
The editor runs in an iframe from Document Server, so pointer events over the editor never reach the host page. The sample therefore puts a thin frame around the editor that belongs to the host page: a <dialog id="editorDialog"> with <div id="editorContainer"> and eight handles (the top edge is a <button>, the rest are <div class="handle"> elements with a data-edge value).
Why this matters: the dialog, not the editor, owns the pointer, so you control the window behavior with plain DOM code.
Editor Config for a Dialog
openEditor(config) creates new DocsAPI.DocEditor() with editorConfig.customization.close (visible: true, text: "Close"), compactHeader: true, width and height of "100%", onAppReady to mark the editor ready, and onRequestClose to call dialog.close(). The dialog is sized to at most 1100 × 720, centered and opened with dialog.showModal().
Why this matters: the cross button appears only when both close and onRequestClose are set. Miss one, and users have no way to close the editor from inside it.
Moving, Resizing and Closing
Handles capture the pointer on pointerdown, with a minimum size of 480 × 320. The dialog is moved and resized in place, because moving the iframe to another element makes the browser reload it. While dragging, the iframe gets pointer-events: none. Arrow keys move the dialog, and Shift with the arrow keys resizes it.
On Esc, the sample cancels the cancel event and calls requestClose() once the editor is ready; on close, it calls destroyEditor(). If the editor fails to load, there is no cross button, so the sample page suggests a custom close button, for example from onError.
Watermark: Config First, Then Runtime Updates
The initial watermark lives in document.options.watermark_on_draw, and %user_name% is replaced with editorConfig.user.name. The sample uses a rectangle rotated by -45 degrees with transparent: 0.3 and the text "Confidential: %user_name%".
When the user clicks Apply, the sample sends the new watermark as a JSON string:
connector.executeMethod("SetProperties", [{ watermark_on_draw: JSON.stringify(buildWatermark()) }])
Why this matters: per the reference, this watermark is drawn on every page while the document is open, added to PDF and image downloads, and never saved to the document. It is not access control, so restrict download, print and copy in the permissions as well.
The connector (Automation API) is available only for ONLYOFFICE Docs Developer, as a premium feature at an extra cost.
Running the Sample
- Open the dialog sample, choose a document type and click Open in a dialog.
- Open the watermark sample, set color, opacity and angle, and click Apply.
- Move the code into your integration and replace the document config with your own.
Where to Take It Next
- Add a custom close button that appears from
onError. - Fill
%user_name%from your auth system and escape quotes and backslashes in the name. - Switch the watermark text when a document changes status (draft, approved).
- Combine both: open the editor in a dialog with a per-user watermark.
To get started, check the document config reference.
Useful Links
About the author
Tech content creator at ONLYOFFICE. Author of how-to articles, contributor on GitHub, switched from outdated Windows to Kubuntu, have been working with open-source office software since 2017.
Comments
Join the discussionNo comments yet. Be the first to comment.




