Products Technologies Demo Docs Blog Support Company

This blog post contains outdated information.

The cited code snippets may be workarounds, and be part of the official API in the meantime.

Using the ASP.NET MVC DocumentViewer JavaScript API

The MVC DocumentViewer is an HTML5 based control to view TX Text Control supported document formats in all browsers. It is an MVC HtmlHelper and can be easily integrated into an MVC view: This tutorial shows how to create a new MVC application using the DocumentViewer: Creating an ASP.NET MVC DocumentViewer application with Razor The available settings that can be adjusted in the view are documented here: DocumentViewerSettings Class documentation Additionally, the DocumentViewer also…

Using the ASP.NET MVC DocumentViewer JavaScript API

The MVC DocumentViewer is an HTML5 based control to view TX Text Control supported document formats in all browsers. It is an MVC HtmlHelper and can be easily integrated into an MVC view:

@Html.TXTextControl().DocumentViewer(settings =>
{
    settings.DocumentPath = Server.MapPath("~/App_Data/Demo.rtf");
    settings.Dock = DocumentViewerSettings.DockStyle.Window;
    settings.IsSelectionActivated = true;
    settings.ShowThumbnailPane = true;
}).Render()

This tutorial shows how to create a new MVC application using the DocumentViewer:

Creating an ASP.NET MVC DocumentViewer application with Razor

The available settings that can be adjusted in the view are documented here:

DocumentViewerSettings Class documentation

Additionally, the DocumentViewer also provides a JavaScript API to adjust the most typical settings client-side. The JavaScript documentation can be found here:

TXDocumentViewer Object documentation

Name Description
toggleToolbar Toggles the toolbar of the document viewer.
toggleSidebar Toggles the sidebar of the document viewer that contains the page thumbnails for faster navigation.
toggleSelection Enables and disables (toggle) the selection feature that enables users to select text lines.
toggleFullscreen Toggles the fullscreen mode.
selectSearchbox Selects the text in the toolbar search input form element.
scrollToPage Scrolls to a specific page. Usage: scrollToPage(int pageNumber)
printDocument Opens the client-side PDF print dialog box to print the current document.
nextSearchResult Navigates to the next or previous search result. Usage: nextSearchResult(bool next)
lockZoom Toggles the zoom lock to 100%.
find Searches for a string in the document. Usage: find(string)
downloadDocument Downloads the document as a PDF.
cancelSearch Clears the search results.

The easiest way to test the JavaScript API is to open the JavaScript console (browser F12 developer tools) and to start typing TXDocumentViewer. The object TXDocumentViewer exposes its members automatically:

Using the ASP.NET MVC DocumentViewer JavaScript API

For example, the following JavaScript code toggles the quick navigation sidebar:

TXDocumentViewer.toggleSidebar();

Most methods are simple calls without any parameters to toggle a specific visual element of the DocumentViewer. Two methods have a parameter: find and scrollToPage. The following code is searching for a specific string in the document:

TXDocumentViewer.find("Text");

The next code snippet scrolls to a specific page in the current document:

TXDocumentViewer.scrollToPage(9);

Try this on your own and join the beta program with the free "go live" license for valid subscribers of TX Text Control .NET Server.

Happy coding!

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

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…


ASP.NETJavaScriptDocument Editor

Detect Toggle Button Changes Using a MutationObserver

This article shows how to detect changes of toggle buttons in the ribbon of the web editor using a MutationObserver. The state of a toggle button in the ribbon visualizes the state of a certain…


ASP.NETJavaScriptDocumentViewer

Using the MVC DocumentViewer in ASP.NET Web Forms

The ASP.NET MVC DocumentViewer for ASP.NET provides more features including document signing capabilities than the DocumentViewer for Web Forms. This article shows how to use the MVC…


ASP.NETJavaScriptComments

Document Collaboration: Implementing Comments with Document Targets

This article explains how to implement comments based on document targets in the online document editor.


ASP.NETDocument ViewerMVC

Configuring ASP.NET and IIS for Larger Requests

Since we released the session-less version of the DocumentViewer, ASP.NET projects must be prepared for sending larger POST data when loading documents from memory.