Getting started with WebViewer

78 views
Skip to first unread message

Andrea Preite

unread,
Jan 14, 2015, 6:46:33 AM1/14/15
to pdfnet-w...@googlegroups.com
Good morning,
I am considering to use WebViewer for a project. I need pdf files to be visible inside a web page and I think that WebViewer can be a good choise for that.

I am trying to create a sample web page, but I am having problems: when I try to instantiate an instance of PDFTron.WebViewer, an exception is thrown, with the message "'$' non è definito" ("'$' is undefined").

Am I doing something wrong?

Thanks a lot and regards.

This is the html code I wrote:

<html>
<head>
<script type="text/javascript" src="WebViewer/lib/WebViewer.min.js"></script>

<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="WebViewer.min.js"></script>

<!-- WebViewer Universal Theming -->
<link type="text/css" rel="stylesheet" href="WebViewer/lib/resources/themes/cloud/jquery-ui-1.10.0.custom.min.css">
<link type="text/css" rel="stylesheet" href="WebViewer/lib/resources/themes/classic/icons.css"> <!-- use the extra icon set for the classic theme -->
<link type="text/css" rel="stylesheet" href="WebViewer/lib/resources/themes/classic/icons.css" media="screen"> <!-- use the extra icon set for the classic theme -->

<script type="text/javascript">
function er(){
var viewerElement = document.getElementById('viewer');
document.getElementById('state').innerHTML = "step1";
try{
var myWebViewer = new PDFTron.WebViewer({type: "html5,Silverlight,flash", initialDoc: "http://pdftron.s3.amazonaws.com/files/xod/NY_fun_list.xod"}, viewerElement);
document.getElementById('state').innerHTML += "</br>step2";
}
catch(e){
document.getElementById('state').innerHTML += "</br>"+e.message;
}
}
</script>
</head>
<body>
<p>
Test
</p>
<div id="viewer">
</div>
<div id="state">
bbb
</div>
<script>
er();
</script>
</body>
</html>

Matt Parizeau

unread,
Jan 14, 2015, 1:24:39 PM1/14/15
to pdfnet-w...@googlegroups.com
Hi,

You need to make sure to load jQuery first before loading WebViewer.min.js as that file depends on jQuery. It's also unclear if you're loading jQuery from the correct location because it seems like you're referring to WebViewer.min.js as being from WebViewer/lib/WebViewer.min.js which would make jQuery be from WebViewer/jquery-1.7.2.min.js (in the default structure).

One other thing once you have that working is that you may have to set the "path" option in the WebViewer constructor to point to the lib folder relative to your html file. So for example path: "WebViewer/lib"

Matt Parizeau
Software Developer
PDFTron Systems Inc.
Reply all
Reply to author
Forward
0 new messages