When using MobileReaderControl.html directly, how to specify license key?

231 views
Skip to first unread message

Nicolai Henriksen

unread,
Jul 28, 2016, 7:24:40 PM7/28/16
to PDFTron WebViewer
We are using the MobileReaderControl.html in iOS and Android apps in the same way as the PDFTron examples do.

But how do we specify the license key?

Everything seems to work without it so perhaps it is not necessary?

Previously we used a custom bit of html that instantiated using new PDFTron.WebViewer() and with a "l" key in the options hash, but that stopped working with the 2.2.0 update.

- Nicolai

Matt Parizeau

unread,
Jul 29, 2016, 3:14:16 PM7/29/16
to PDFTron WebViewer
Hi Nicolai,

The license key only needs to be passed to WebViewer when using PDFNetJS. When using XOD files you use your license key at conversion time with PDFNet or DocPub (otherwise the documents will have a watermark) so it isn't required to be passed to the viewer.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Nicolai Henriksen

unread,
Aug 2, 2016, 1:26:52 PM8/2/16
to PDFTron WebViewer
Ah, ok. Cool

 - Nicolai

Dũng Nguyễn

unread,
Apr 23, 2018, 12:53:23 PM4/23/18
to PDFTron WebViewer
Hi Matt,

I have the same problem, my code is:
      var myWebViewer = new PDFTron.WebViewer({
                path: '/WebViewer/lib/',
                pdfnet: true,
                type: "html5,html5Mobile",
                mobileRedirect: true,
                l: 'my license',
                initialDoc: '/WebViewer/pdfs/default.pdf'
            },
            viewerElement);
It works fine on desktop browser, however, when I open from mobile, it show a alert 'A license key for WebViewer is required....'.
How to set license for mobileviewer?
I have PDFNetJS Core SDK license.

Vào 02:14:16 UTC+7 Thứ Bảy, ngày 30 tháng 7 năm 2016, Matt Parizeau đã viết:

Matt Parizeau

unread,
Apr 24, 2018, 3:11:20 PM4/24/18
to PDFTron WebViewer
Hi Dung,

You can either set mobileRedirect to false (this would mean it stays inside the iframe which might not be desirable) or you can add the following at the top of your config file:

window.WebViewer = {
  l
: function() {
   
return 'LICENSE_KEY_GOES_HERE';
 
}
};

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Knowdex, LLC

unread,
May 2, 2018, 1:01:15 PM5/2/18
to PDFTron WebViewer
Hi Matt:

I am having a similar issue. On my desktop browser everything is working perfectly. However when I got to my iPhone/iPad I am getting the following error: `Worker encountered an error. This is most likely due to browser incompatibility or memory constraints.`

This is my index.html

```
<!DOCTYPE html>
<html style="height:100%;">
<head>
<title>Knowdex Sample</title>
<meta http-equiv="Content-Type" content="text/html">
<script src="jquery-3.2.1.min.js"></script>
<script src="lib/WebViewer.min.js"></script>
<script src="lib/html5/ControlUtils.js"></script>
<script>

$(function() {
var queryParams = window.ControlUtils.getQueryStringMap(false);
var docType = queryParams.getString('doctype', 'pdf');

var viewerElement = document.getElementById('viewer');
var myWebViewer = new PDFTron.WebViewer({
type: 'html5,html5Mobile',
l: "LICENSE_KEY_GOES_HERE",
path: "lib",
initialDoc: "pdf/WebViewer_Developer_Guide." + docType,
documentType: docType,
config: "config.js",
documentId: "WebViewer_Developer_Guide",
enableAnnotations: true,
streaming: false,
}, viewerElement);
});
</script>
</head>

<body style="width:100%;height:100%;margin:0px;padding:0px;overflow:hidden" oncontextmenu="return false;">
<div id="viewer" style="height: 100%; overflow: hidden;"></div>
</body>
</html>
```

and this is my config.js:
```
/**
* ReaderControl config file
* ------------------------------
* This js file is meant to simplify configuring commonly used settings for ReaderControl.
* You can override default settings through ReaderControl.config properties, or add JavaScript code directly here.
*/

window.WebViewer = {
l: function() {
return 'LICENSE_KEY_GOES_HERE'
}
};
(function() {
//=========================================================
// Load a custom script for the "about" page
//=========================================================
$.extend(ReaderControl.config, {
customScript : 'defaultScriptExtension.js'
});

$(document).on('documentLoaded', function() {
// set select as default
readerControl.setToolMode(window.PDFTron.WebViewer.ToolMode.AnnotationEdit);

// two page reader as default
readerControl.setLayoutMode(CoreControls.DisplayModes.FacingContinuous);


if ($.mobile) {
// one page reader as default in mobile
readerControl.setLayoutMode(CoreControls.DisplayModes.Continuous);
}
});

$(document).bind("viewerLoaded", function(event) {

// hide some buttons that aren't implemented

/*
$('.drop-content').hide().prev().hide();
$('#rotateButton').hide().prev().hide();
$('#fitModes').hide().prev().hide();
$('#docpad').remove();
$('#printButton').hide().prev().hide();
$('#fullScreenButton').hide().prev().hide();
$('#optionsButton').hide().prev().hide();
*/

//$('#freeHand').hide().prev().hide();

/*$('#freeText').hide().prev().hide();*/
/*
$('#overflowTools').hide().prev().hide();
$('#copyButton').hide().prev().hide();
$('#downloadButton').hide().prev().hide();
*/
$('#copyButton').hide().prev().hide();
$('#printButton').hide().prev().hide();
$('#downloadButton').hide().prev().hide();

Tools.Tool.prototype.contextMenu = function(e) {
e.preventDefault();
};
ReaderControl.prototype.setContextMenu = function() {};


var isCtrl = false;
document.onkeyup=function(e)
{
if(e.which == 17)
isCtrl=false;
}

document.onkeydown=function(e)
{
if(e.which == 17)
isCtrl=true;
if((e.which == 85) || (e.which == 67) && isCtrl == true)
{
// alert(‘Keyboard shortcuts are cool!’);
return false;
}
if(e.metaKey){
return false;
}
}

});


})();
```
Reply all
Reply to author
Forward
0 new messages