JavaScript API
In the browser, your code controls the Document Editor through the TXTextControl object and the Document Viewer through the TXDocumentViewer object. Both scripts come from DS Server, and both objects are the same whether a client library created the component or your own HTML page did. Their references list every object, property, method and event with its syntax and parameters.
The two objects are independent APIs with their own conventions. Knowing how each one is created and when it is ready makes the reference pages easier to use.
The Two APIs
| Document Editor | Document Viewer | |
|---|---|---|
| Object | TXTextControl | TXDocumentViewer |
| What it controls | The document in the editor: text, formatting, tables, images, fields, sections, tracked changes, comments, the selection and the ribbon | The displayed document: loading and saving, search, printing, annotations, form fields, tracked changes, signatures and the toolbar |
| Script on DS Server | <serviceURL>/documenteditor/JS/ds-server-document-editor.js | <serviceURL>/documentviewer/TextControl/GetResource?Resource=minimized.tx-viewer.min.js |
| Created by | TXTextControl.init | TXDocumentViewer.init |
| Events | addEventListener of TXTextControl, such as textControlLoaded | addEventListener of TXDocumentViewer |
| How methods return results | Asynchronous methods pass their results to callback functions | Loading and saving return promises; most other members return their result directly |
Enumerations of the editor are properties of its object, such as TXTextControl.StreamType, and the viewer has its own, such as TXDocumentViewer.StreamType.
How DS Server Connects the Objects
The JavaScript APIs are TX Text Control's, and DS Server adds how the component reaches the server. The client libraries show the settings they pass:
- Document Editor.
TXTextControl.initreceives thecontainerIDof the element to fill, theserviceURLof DS Server,authSettingswith eitherclientIdandclientSecretor anaccessToken, and theeditorSettingsdescribed by DocumentEditorSettings.serviceURLandauthSettingsbelong to DS Server and are not members of ComponentSettings in the reference. - Document Viewer. The script URL carries the access token in the
access_tokenquery parameter.TXDocumentViewer.initreceives thecontainerIDandviewerSettings, withbasePathset to<serviceURL>/documentviewerand the token inoauthSettings.accessToken. DocumentLoadSettings and SignatureSettings are documented in the reference.
The Angular and React components do all of this and tell you when the object exists: the Angular components raise dsDocumentEditorLoaded and dsDocumentViewerLoaded on document, and the React components call onLoad. Without a component, JavaScript in Getting Started loads the editor from a plain HTML page.
How the Reference Is Organized
Each API has a page per object. The main objects, TXTextControl and TXDocumentViewer, lead to the objects your code reaches through their properties, such as the tables of a document or the annotations in the viewer. The page of an object lists its properties, methods and events, and the page of a member shows its syntax, its parameters and the value or callback it returns. The Document Editor's reference also documents the callback types and the objects that event handlers receive.
Find the Right Page
| If you want to | Read |
|---|---|
| Look up a member of the editor | Document Editor |
| Look up a member of the viewer | Document Viewer |
| Load a document into the editor | loadDocument |
| Offer merge fields from JSON data in the editor | loadJsonData |
| Configure the Angular or React components that create the objects | Angular or React |
| Configure the Document Editor or Document Viewer in an ASP.NET Core view | ASP.NET Core |
Pages in This Section
- Document Editor: the reference of the
TXTextControlobject and the objects below it. - Document Viewer: the reference of the
TXDocumentViewerobject and the objects below it.