You can customize the HTMLViewer interface using JQuery methods. WebViewer control adds JQuery library in page scripts. Use the code in this walkthrough to remove a button from the HTMLViewer toolbar and add a client side PDF export implementation.
This walkthrough is split into the following activities:
When you complete this walkthrough you get an HTMLViewer that looks similar to the following at run time.
To load an ActiveReport in the Web application
To add the jQuery library to the Web application project
Follow the steps below to add the jQuery library to your Web application project.
Add this code after the <head> tag |
Copy Code
|
---|---|
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> |
Add this code before the </script> tag |
Copy Code
|
---|---|
var clientID = ...; $(document).ready(function () { $('#' + clientID).on('loaded', viewer_loaded); }); |
To access the WebViewer view model
The HTML Web Viewer is created using the MVVM pattern that provides a view model which does not depend on the UI. The code can access the Viewer's view model and bind the custom UI to it by using well-documented properties and methods. For MVVM support, the code can use knockout.js which is the standard MVVM library for JavaScript. Knockout.js provides declarative bindings, observable objects and collections in HTML markup. See Using Javascript with the HTML Viewerfor more information.
Follow the steps below to access the ViewModel.
Add a script tag like the following before the body tag |
Copy Code
|
---|---|
<script language="javascript" type="text/javascript"> </script> |
Paste the code into .aspx source |
Copy Code
|
---|---|
<script language="javascript" type="text/javascript"> |
Paste the code into .aspx source |
Copy Code
|
---|---|
var viewModel = GetViewModel('WebViewer1'); |
Paste the code into .aspx source |
Copy Code
|
---|---|
$('#WebViewer1').bind('loaded', viewer_loaded); |
To remove a button from the WebViewer toolbar
In the Source view of the Default.aspx file, add the following Javascript code inside the viewer_loaded event handler to access the WebViewer toolbar and remove the Next Page button from the toolbar:
Paste the code into .aspx source |
Copy Code
|
---|---|
var toolbar = $('#WebViewer1').find('.arvToolBar'); |
Note: In order to access the child elements of the WebViewer toolbar you need their css class names. Following is a list for reference:
Toolbar Child Elements
To add a function for exporting to PDF
The steps below illustrate how to build a custom UI.
Paste the code into .aspx source |
Copy Code
|
---|---|
function exportPDF() var viewModel = GetViewModel('WebViewer1'); if (viewModel.PageLoaded()) |
Paste the code into .aspx source |
Copy Code
|
---|---|
<div id="customToolbar" style = "display:inline"> |
Paste the code into .aspx source |
Copy Code
|
---|---|
$('#customToolbar').appendTo(toolbar); |
To bind the custom UI to the WebViewer view model and run the application
Paste the code into .aspx source |
Copy Code
|
---|---|
ko.applyBindings(viewModel, document.getElementById("customToolbar")); |