No Document Service? No Problem!

Use it or don’t. That’s now up to you when it comes to using the LEADTOOLS Document Viewer with the Document Service. In the past, the Document Service was always required, but the LEADTOOLS update in March introduced the capability to use the HTML5/JavaScript Document Viewer without the Document Service. Choosing to use the viewer without the service will have some limitations as you won’t be able to send anything to a server to make .NET calls, but it still useful. This blog will walk you through everything needed to use the LEADTOOLS Document Viewer without the Document Service.


Disable the service interaction

This can easily be achieved by setting the service configuration variables to null.


	lt.Document.DocumentFactory.serviceHost = null;
	lt.Document.DocumentFactory.servicePath = null;
	lt.Document.DocumentFactory.serviceApiPath = null;
	lt.Document.DocumentFactory.localProxyUrlTemplate = null;

Include/configure the PDF client-side rendering dependencies

The following JavaScript files will need to be added to your index.html.


	<script type="text/javascript" src="Scripts/Leadtools.Pdf.js"></script>
	<script type="text/javascript" src="Scripts/Leadtools.Pdf.Worker.js"></script>

You’ll then need to point to the character map files and web-worker, both included with our SDK.


	PDFJS.cMapPacked = true;
	PDFJS.cMapUrl = "Resources/Cmaps/";
	PDFJS.workerSrc = "Scripts/Leadtools.Pdf.Worker.js";

Finally, add the compatibility helper which ensures different browsers behave identically. Again, this will go in your index.html file (after the above code).


	<script type="text/javascript" src="Scripts/Leadtools.Pdf.Compatibility.js"></script>

Enable client-side rendering

This can be achieved by setting usePDFRendering and usePDFText to true.


	documentViewer.usePDFRendering = true;
	documentViewer.usePDFText = true;

Load a file

With the addition of this support, we’ve also added the loadFromFile option to our DocumentFactory. This method allows you to load in a native File object (acquired from a file input) for viewing.


	lt.Document.DocumentFactory.loadFromFile(documentFile, loadOptions);

To test this with the latest version of LEADTOOLS, download the free 60 day evaluation straight from our site. If you have any comments or questions regarding this, feel free to comment on this post or contact our Support department at support@leadtools.com.

This entry was posted in HTML5. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *