DS Server

React

Topic

React applications add the Document Editor and the Document Viewer of DS Server with two npm packages, each exporting one component: DocumentEditor and DocumentViewer. The component loads its script from DS Server, authorizes itself and creates the editor or viewer inside its div element. Below are the properties and defaults of version 5.0.0, read from the README and the published code of each package, and what to change for Vite 8.

For a first application, follow the Getting Started tutorials Document Editor in React and Document Viewer in React.

Packages and Requirements

PackageVersionComponentreact and react-dom
@txtextcontrol/tx-react-ds-document-editor5.0.0DocumentEditor^19.0.0
@txtextcontrol/tx-react-ds-document-viewer5.0.0DocumentViewer^19.0.0

Both packages need React 19 and are meant for DS Server 5.0.0; the viewer's README says 5.0.0 or later. You also need a security profile of your DS Server, or a trial token, as Overview explains.

Install the Packages

The READMEs create the application with Vite, choosing React as the framework and JavaScript as the language, and then install the package:

npm create vite@latest my-app
cd my-app
npm i @txtextcontrol/tx-react-ds-document-editor
npm i @txtextcontrol/tx-react-ds-document-viewer

Import the Components in Vite 8

The packages are CommonJS modules. A project created with Vite 8 is an ES module project ("type": "module" in package.json), and Vite 8 then returns the whole CommonJS module for a default import instead of the component. The plain default import the READMEs show fails, and React reports an invalid element type. Take the component from the default export when it is there:

import DocumentEditorPackage from '@txtextcontrol/tx-react-ds-document-editor';
import DocumentViewerPackage from '@txtextcontrol/tx-react-ds-document-viewer';

// Vite 8 returns the CommonJS module for a default import
const DocumentEditor = DocumentEditorPackage.default ?? DocumentEditorPackage;
const DocumentViewer = DocumentViewerPackage.default ?? DocumentViewerPackage;

With Vite 7 and other bundlers that return the component itself, the same lines work unchanged. The examples below assume these two constants.

DocumentEditor

Add the editor to App.jsx:

function App() {
  function handleLoad() {
    // TXTextControl exists from now on
    TXTextControl.addEventListener('textControlLoaded', () => {
      console.log('The Document Editor is ready.');
    });
  }

  return (
    <DocumentEditor
      style={{ width: '1280px', height: '1024px' }}
      serviceURL="https://ds.example.com"
      authSettings={{ clientId: '<client ID>', clientSecret: '<client secret>' }}
      onLoad={handleLoad}
    />
  );
}

export default App;

serviceURL is required and must start with http:// or https://; otherwise, the component throws the error Invalid service URL.

PropertyTypeDefaultDescription
serviceURLstringnoneThe URL of DS Server
authSettingsobjectnoneThe credentials: clientId and clientSecret of the security profile, or an accessToken your application has requested
styleobject{ width: '100%', height: '1000px', display: 'inline-block' }The style of the editor's container, such as its width and height in pixels or percent
editModestring'Edit''Edit', 'ReadAndSelect', 'ReadOnly' or 'UsePassword'
contextMenusEnabledbooleannot setWhether a right-click opens a context menu
formattingPrinterstring''The name of a printer whose text dimensions and capabilities are used to format the document
culturestring''The culture for formats such as dates and times, such as 'de-DE'
uiCulturestring''The culture of the user interface strings, such as 'en-US'
userNamesstring[][]The users who can edit the editable regions assigned to them when the document is read-only
reconnectTimeoutnumber0The time in seconds after which the editor stops trying to reconnect after the connection is lost
customQueryParamsobject{}Query parameters the editor adds to the address of its WebSocket connection
onLoadfunctionnoneCalled when the editor script has loaded, after the component has called TXTextControl.init; the TXTextControl object exists then

A style passed in style replaces the whole default, so set display: 'inline-block' yourself if you want it. Unlike the Angular component, the React editor has no property for a document or a data source: load them in onLoad with the methods of the TXTextControl object, such as loadDocument and loadJsonData, after the editor has raised textControlLoaded.

DocumentViewer

Add the viewer to App.jsx:

function App() {
  return (
    <DocumentViewer
      width="1280px"
      height="1024px"
      serviceURL="https://ds.example.com"
      clientId="<client ID>"
      clientSecret="<client secret>"
      documentData="SGVsbG8gdGhlcmU="
    />
  );
}

export default App;

The viewer takes the credentials as separate properties, not in an object. documentData holds the document as a Base64-encoded string; the example shows the text "Hello there".

PropertyTypeDefaultDescription
serviceURLstringnoneThe URL of DS Server
clientIdstringnoneThe client ID of the security profile
clientSecretstringnoneThe client secret of the security profile
accessTokenstringnoneAn access token your application has requested; used when clientId isn't set
widthstringnoneThe width of the component, such as "1280px"
heightstringnoneThe height of the component
documentDatastringnoneThe document to display, Base64-encoded
documentPathstringnoneThe document name the viewer displays
dockstring'Fill'How the viewer is docked: 'Fill' or 'Window'
toolbarDockedbooleantrueWhether the toolbar is docked or floating
isSelectionActivatedbooleantrueWhether text can be selected and copied
showThumbnailPanebooleantrueWhether the thumbnail pane is visible
userNamesstring[][]The users who have access to editable regions
resourcesobjectEnglish stringsStrings of the user interface, as pairs of resource name and text
signatureSettingsobjectsee belowThe settings of a signature process
onLoadfunctionnoneCalled when the viewer script has loaded; the TXDocumentViewer object exists then

The README spells the client ID property clientID, but the component reads clientId. The README also lists customQueryParams, which version 5.0.0 of the component doesn't pass to the viewer. The component supports showThumbnailPane, which the README leaves out. The component passes the signatureSettings object on to the viewer, so it also accepts defaultSignatureFont of the viewer's SignatureSettings, which the README doesn't list.

Signature Settings

PropertyTypeDefaultDescription
showSignatureBarbooleanfalseWhether the signature bar is shown
ownerNamestring''The name of the document owner
signerNamestring''The name of the signer
signerInitialsstring''The initials of the signer
signatureBoxesobject[][]The boxes to sign; when the array isn't empty, signatureBoxName has no effect
signatureBoxNamestring'txsign'Deprecated: the name of the signature box; use signatureBoxes
defaultSignatureFontobjectnoneThe default font of text-based signatures: family, a CSS font family
uniqueIdstring''A unique ID of the signature
redirectUrlAfterSignaturestring''The URL to which DS Server sends the signed document in an HTTP POST request after a successful signing process, as a SignatureData object (see Custom Signing Endpoints)
customSigningbooleanfalseWhether your own code handles the signing process

A signature box has a name, the name of the signature field, a style, "Signature", the default, or "Initials", and signingRequired, which is true by default:

<DocumentViewer
  width="1280px"
  height="1024px"
  serviceURL="https://ds.example.com"
  clientId="<client ID>"
  clientSecret="<client secret>"
  documentData="SGVsbG8gdGhlcmU="
  signatureSettings={{
    showSignatureBar: true,
    ownerName: 'Paul',
    signerName: 'Jacob',
    signerInitials: 'JK',
    redirectUrlAfterSignature: 'https://your.app/signed',
    signatureBoxes: [{ name: 'txsign', signingRequired: true, style: 'Signature' }]
  }}
/>

Once the viewer is loaded, your code works with the TXDocumentViewer object of the Document Viewer's JavaScript API.

How the Components Authorize

With a client ID and a client secret, both components request their access token from DS Server with the client credentials grant type, which the security profile must allow, and the credentials are part of the JavaScript the browser downloads. To keep them on the server, request the token there and pass it to the component: authSettings={{ accessToken: token }} for the editor, accessToken={token} for the viewer. Overview compares the options.