Pdf.js: ReferenceError: pdfjsViewer is not defined

Created on 11 Feb 2019  路  3Comments  路  Source: mozilla/pdf.js

In summary, I'm trying the Acroform example. I'm trying to view a pdf hosted on my server but it is giving me the error: Uncaught (in promise) ReferenceError: pdfjsViewer is not defined

Attach (recommended) or Link to PDF file here: The file is hosted on my server.

Configuration:

  • Web browser and its version: Google Chrome Version 72.0.3626.96 (Official Build) (64-bit)
  • Operating system and its version: Windows 10
  • PDF.js version: v2.1.245
  • Is a browser extension: no

I'm getting the error at var pdfPageView = new pdfjsViewer.PDFPageView({

The code is as below:

pdfjsLib.GlobalWorkerOptions.workerSrc = "/js/Lib/pdf.worker.js";
    var DEFAULT_SCALE = 1.0;
    var container = document.getElementById('viewer_container');
    var loadingTask = pdfjsLib.getDocument(pathStringer);

    loadingTask.promise.then(function (doc) {
        // Use a promise to fetch and render the next page.
        var promise = Promise.resolve();

        for (var i = 1; i <= doc.numPages; i++) {
            promise = promise.then(function (pageNum) {
                return doc.getPage(pageNum).then(function (pdfPage) {
                    // Create the page view.
                    var pdfPageView = new pdfjsViewer.PDFPageView({
                        container: container,
                        id: pageNum,
                        scale: DEFAULT_SCALE,
                        defaultViewport: pdfPage.getViewport({ scale: DEFAULT_SCALE, }),
                        annotationLayerFactory:
                            new pdfjsViewer.DefaultAnnotationLayerFactory(),
                        renderInteractiveForms: true,
                    });

                    // Associate the actual page with the view and draw it.
                    pdfPageView.setPdfPage(pdfPage);
                    return pdfPageView.draw();
                });
            }.bind(null, i));
        }
    });

1-other

All 3 comments

I'm getting the error at var pdfPageView = new pdfjsViewer.PDFPageView({

WFM, when following the instructions at https://github.com/mozilla/pdf.js/tree/master/examples/acroforms#getting-started.

The example should work. Make sure not for forget the dist-install step.

My bad. Instead of using the viewer from pdfjs-dist which is located at
pdf.js\node_modules\pdfjs-dist\web\pdf_viewer.js , I was using viewer at pdf.js\web\viewer.js.

Was this page helpful?
0 / 5 - 0 ratings