TX Text Control .NET Server

React API

Topic

DocumentEditor and DocumentViewer are the React components of the Document Editor and the Document Viewer, each in an npm package of its own. The tables below list every property the components read, with its type, its default value and what it does, taken from the README and the code published with the packages. Keep them at hand while you configure a component in a React application.

Neither component has methods of its own. Once it has loaded, your code works with the document through the JavaScript objects TXTextControl and TXDocumentViewer, which JavaScript API introduces.

Packages

PackageVersionComponentreact and react-dom
@txtextcontrol/tx-react-document-editor34.0.0DocumentEditor^19.2.0
@txtextcontrol/tx-react-document-viewer34.0.0DocumentViewer^18.2.0

Each package has a default export, the component, and no named exports. Both packages are CommonJS modules, so in a project created with Vite 8 the default import returns the whole module object and the component is its default property, as Import the Components in Vite 8 shows. React in the Installation Guide explains the React versions the packages declare.

DocumentEditor

webSocketURL is required: without it, the component throws the error "Please provide a WebSocket URL." when it is mounted. The size is set with style, not with width and height properties.

PropertyTypeDefaultDescription
webSocketURLstringnullThe WebSocket URL of the backend, such as wss://localhost:7118/api/TXWebSocket
styleobject{ width: "1000px", height: "800px", display: "inline-block" }The style of the container element; width and height take pixel or percent values
editModestring"Edit"Whether the text can be edited, only selected or only read: "Edit", "ReadAndSelect", "ReadOnly" or "UsePassword"
contextMenusEnabledbooleantrueWhether a right-click opens a context menu
culturestring""The culture for formatting, such as dates and times, for example "de-DE"
uiCulturestring""The culture of the user interface strings, for example "en-US"
userNamesstring[][]The users who can edit the editable regions assigned to them when the document is read-only
formattingPrinterstring""The name of a printer whose text dimensions are used to format the document
reconnectTimeoutnumber0The time in seconds after which the editor stops trying to reconnect when the connection is lost
onLoadfunctionnoneCalled when the editor script has loaded and the TXTextControl object exists

The React component has fewer settings than the Angular component: it passes only the properties above to TXTextControl.init. Other settings, such as control characters or table grid lines, are properties of the TXTextControl object that your code sets after the editor has loaded.

The onLoad Callback

The component loads the editor script from the backend when it is mounted: it replaces ws or wss in webSocketURL with http or https, appends /GetResource?name=tx-document-editor.min.js to the path and adds the query string of webSocketURL, such as an access token. When the script has loaded, it calls TXTextControl.init and then onLoad.

At this point, the TXTextControl object exists, but the document isn't ready yet: attach a handler to the editor's textControlLoaded event with addEventListener before you change the document. Load, Save and Remove the Editor in the Integration Guide shows the code, and Events lists the order of the events during initialization.

DocumentViewer

width, height and basePath are required.

PropertyTypeDefaultDescription
widthstringnoneThe width of the viewer, such as "1024px"
heightstringnoneThe height of the viewer, such as "1024px"
basePathstringnoneThe URL of the backend that hosts the Document Viewer, such as https://localhost:7275
documentDatastringnoneThe document to show, as a Base64 string
documentPathstringnoneThe name of the document that the viewer shows
documentLoadSettingsobjectnoneloadEmbeddedComments loads the comments of the document as annotations; pdfjs holds workerSourcePath and librarySourcePath, the paths of the PDF.js worker and library
dockstring"Fill"How the viewer is docked: "Fill" or "Window"
toolbarDockedbooleantrueWhether the toolbar is docked or floating
isSelectionActivatedbooleantrueWhether users can select and copy text
showThumbnailPanebooleantrueWhether the sidebar with page thumbnails is shown
signatureSettingsobjectsee belowThe settings of the signature process
userNamesstring[][]An array of user names; the README describes them as the users who have access to editable regions
resourcesobjectthe English stringsReplacements for the strings the viewer displays, as key-value pairs
onLoadfunctionnoneCalled when the viewer script has loaded

The component requests the viewer script from <basePath>/TextControl/GetResource?Resource=minimized.tx-viewer.min.js and passes basePath to the viewer without its query string. A query string in basePath is added only to the request of the script.

signatureSettings

PropertyTypeDefaultDescription
showSignatureBarbooleanfalseWhether the signature bar is shown
ownerNamestring""The name of the owner who requests the signature
signerNamestring""The name of the signer
signerInitialsstring""The initials of the signer
signatureBoxNamestring"txsign"The name of the signature box in the document; ignored when signatureBoxes isn't empty
signatureBoxesobject[][]Several signature boxes, each with name, style ("Signature" or "Initials", "Signature" by default) and signingRequired (true by default)
uniqueIdstring""The unique ID of the signature
redirectUrlAfterSignaturestring""The URL of an endpoint to which the viewer's controller posts the signature data after a successful signature
customSigningbooleanfalseWhether your own code handles the signing process

The .NET counterpart is the SignatureSettings class of the ASP.NET Core HTML helper, whose reference describes the properties in detail. Digital Signatures shows the signature process.

Use the Viewer From Your Code

The viewer raises the documentViewerLoaded event on the window object when the TXDocumentViewer object is ready. Document Viewer with React handles it in useEffect to load documents.