Sample Code not working

683 views
Skip to first unread message

Ashish Deshpande

unread,
Jun 7, 2016, 12:27:43 PM6/7/16
to PDFTron WebViewer
http://pdftron.com/webviewer/pdfnetjs/tutorials/PDFNet/starting-out.html


The sample code in JS given in the above link is throwing errors , i  have attached a jpg file showing the errors i have followed step by step same as instructed still showing errors 
Can u please suggest where m i going wrong 

Captuggggggre.JPG

Maxim Tsai

unread,
Jun 9, 2016, 4:20:27 PM6/9/16
to PDFTron WebViewer
Hello Ashish,

Based on the error messages there seem to be two error sources.

Error 1, "Uncaught ReferenceError: runSampleTest is not defined":

After trying out the tutorial I noticed there was a syntax error in the SampleTest.js file for the tutorial (which will be fixed with the next website update).

To fix the error, add the line "var runSampleTest" to the first line of the SampleTest.js test. Alternatively you could remove the "use strict" line to make the error disappear.

http://i.imgur.com/jY9UsOl.png

Error 2, "404 (Not Found)".

This error tends to happen if the "WebViewer" folder is renamed to any other name eg. "WebViewer - Copy". If this was not the issue, can you send me a screenshot of how your project was set up and the contents inside the WebViewer folder (to make sure all the files are inside).

ex. http://i.imgur.com/aZjE8x1.png
http://i.imgur.com/TjqgDAa.png

Feel free to ask if you are still encountering errors.

Pawan Kumar

unread,
Jun 16, 2016, 12:56:07 PM6/16/16
to PDFTron WebViewer
Hi,

I am also facing the same error and even after following the steps given by Maxim, I am still facing the issue.
I have removed the 'use strict' which resolved the first issue however 2nd issue mentioned by Ashish is still there. My both files SampleTest.html and SampleTest.js are at proper location as mentioned in the tutorial. 
Can someone look into this?

- Pawan
pdfnetjs error.png

Maxim Tsai

unread,
Jun 17, 2016, 2:15:26 PM6/17/16
to PDFTron WebViewer
Hello Pawan

I have not been able to reproduce the same errors that you are getting, but here is a download link to my setup for the sample: http://www.filedropper.com/pdfnetjsdemoapplication (35 mb). The sample once run should display: "Test Complete! Your file has 0 pages".

If my sample still results in errors, send me a zipped up version of your setup so I can see what problems there might be.

Matt Parizeau

unread,
Jun 17, 2016, 3:36:14 PM6/17/16
to pdfnet-w...@googlegroups.com
Hi Pawan,

Another thing that might be going wrong is that the proper mime types aren't set on your server which is why you're getting a 404 (this is most common on IIS).

For PDFs the mimetypes you'll want to add are:
.mem application/octet-stream
.res application/octet-stream
.pexe application/x-pnacl
.nmf application/octet-stream
.wasm application/wasm

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Pawan Kumar

unread,
Jun 20, 2016, 1:07:49 PM6/20/16
to PDFTron WebViewer
Thanks Matt,

This resolved my error. MIME types were not set in local IIS.

Regards,
Pawan


On Saturday, 18 June 2016 01:06:14 UTC+5:30, Matt Parizeau wrote:
Hi Pawan,

Another thing that might be going wrong is that the proper mime types aren't set on your server which is why you're getting a 404 (this is most common on IIS).

For PDFs the mimetypes you'll want to add are:
.mem application/octet-stream
.res application/octet-stream
.pexe application/x-pnacl
.nmf application/octet-stream

Narendra Chowdary Manam

unread,
Jul 27, 2017, 12:24:08 PM7/27/17
to PDFTron WebViewer
Hello Team,

I am also facing same problem, I am trying to create web page using web viewer and PDFNetJs, By using below code

http://pdftron.com/webviewer/pdfnetjs/tutorials/PDFNet/viewer.html


But I am getting errors, Please refer below link for more info

https://ibb.co/gZyUS5






Justin Jung

unread,
Jul 27, 2017, 7:01:41 PM7/27/17
to PDFTron WebViewer
Hello,

Since you are getting 404 on those specific files, it looks like the MIME types for those extensions are not set correctly.
Did you try setting MIME types as suggested in the previous messages of the thread?

Justin Jung

Narendra Chowdary Manam

unread,
Jul 28, 2017, 11:57:13 AM7/28/17
to PDFTron WebViewer
I Tried with below code

<!DOCTYPE html>
    <head>
        <title>PDF Sample Program</title>
        <meta http-equiv="Content-Type" content="text/html">
        <script src="WebViewer/jquery-3.2.1.min.js"></script>
        <script src="WebViewer/lib/WebViewer.min.js"></script>
        <script type="text/javascript">
    $(function () {
        var ViewerElement = document.getElementById("viewer");
        var myWebViwer = new PDFTron.WebViewer({
            type: "html5",
            path: "WebViewer/lib",
            initialDoc: "WebViewer/mydoc.pdf",
            l: "demo:narendr...@gmail.com:70b706bd016cb983e1ad9ad07cd28edf819002597035490e5a"
        }, ViewerElement);
    });
        </script>

    </head>
    <body>
        <div id="viewer"></div>
    </body>
</html>


Could you please assist me?

Justin Jung

unread,
Jul 28, 2017, 6:54:35 PM7/28/17
to PDFTron WebViewer
First you should try configuring correct mime types in the server so that the browser can open files with proper extension/plugin. For example, here is a link of how to add a mime type in IIS 7:
Reply all
Reply to author
Forward
0 new messages