Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: pdfjsViewer is not defined #10543

Closed
smit-modi opened this issue Feb 11, 2019 · 3 comments
Closed

ReferenceError: pdfjsViewer is not defined #10543

smit-modi opened this issue Feb 11, 2019 · 3 comments
Labels

Comments

@smit-modi
Copy link

smit-modi commented Feb 11, 2019

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));
        }
    });

@Snuffleupagus
Copy link
Collaborator

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.

@timvandermeij
Copy link
Contributor

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

@smit-modi
Copy link
Author

smit-modi commented Feb 13, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants