Products Technologies Demo Docs Blog Support Company

Getting Started: Document Viewer with JavaScript

This article shows how to use the TX Text Control document viewer in a pure HTML and JavaScript environment.

Getting Started: Document Viewer with JavaScript

Prerequisites

There are two ways to evaluate the TX Text Control Document Viewer. You can either host your own backend by downloading the trial version of TX Text Control .NET Server, or by creating a trial access token to use a hosted backend, valid for 30 days:

Creating the Application

To load the initial JavaScript, the backend provides an endpoint that returns the required JavaScript. This endpoint can be used in a script tag in HTML to embed the required JavaScript code.

<script src="https://backend.textcontrol.com/TextControl/GetResource?Resource=minimized.tx-viewer.min.js"></script>
<script src="https://backend.textcontrol.com/TextControl/GetResource?Resource=minimized.tx-viewer-component.min.js"></script>

Backend

The above script references the hosted test backend. If you host it yourself, replace the URL with your backend.

The Document Viewer is a Web Component. Each instance uses an encapsulated shadow DOM with it's own style and markup. The element name of the Web Component is <tx‑document‑viewer> and can be simply added to any HTML page:

<tx-document-viewer
  id="viewer1"
  settings='{"documentData":"VGV4dCBDb250cm9s", "dock":1, "basePath":"https://backend.textcontrol.com"}'>
</tx-document-viewer>

The complete HTML page would look like this. The element in which the editor is created is the div element with the id txDocumentEditor.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>TX Text Control Document Viewer from JS</title>
  <script src="https://backend.textcontrol.com/TextControl/GetResource?Resource=minimized.tx-viewer.min.js"></script>
  <script src="https://backend.textcontrol.com/TextControl/GetResource?Resource=minimized.tx-viewer-component.min.js"></script>
  <style>
    #txDocumentViewer {
      height: 800px;
      width: 800px;
    }
  </style>
</head>
<body>

  <tx-document-viewer
    id="viewer1"
    settings='{"documentData":"VGV4dCBDb250cm9s", "dock":1, "basePath":"https://backend.textcontrol.com"}'>
  </tx-document-viewer>

</body>
</html>

Learn More

This article gives an overview of the advantages and how those Web Components are integrated.

TX Text Control DocumentViewer Becomes a Web Component

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

JavaScriptASP.NET CoreDOCX Editor

How to Embed a DOCX Editor in a Web Application (ASP.NET Core)

This tutorial shows how to embed a DOCX editor in an ASP.NET Core web application with TX Text Control. It covers setting up the editor, loading a DOCX document, and editing it with true WYSIWYG…


AngularASP.NETJavaScript

Building an ASP.NET Core Backend Application to Host the Document Editor and…

This article explains how to create an ASP.NET Core backend application to host the Document Editor and Document Viewer. This backend application is required to provide the required functionality…


JavaScriptASP.NET CoreDocument Editor

Getting Started: Document Editor with JavaScript

This article shows how to use the TX Text Control document editor in a pure HTML and JavaScript environment.


ReactASP.NET CoreDOCX Editor

React DOCX Editor: Add Word-Like Editing to Your Web App

This tutorial shows how to add a React DOCX editor to your web application with TX Text Control .NET Server. It covers setting up the backend, adding the Document Editor component, and loading and…


AngularJavaScriptReact

DOCX Editor SDK: A Complete Evaluation Guide and Checklist

The right DOCX Editor SDK brings Microsoft Word-like editing into your web application and fits your technical and business requirements. This guide covers the capabilities and business…

Share this blog post on:

​​​