Pdf.js: MessageHandler Undefined

Created on 2 Oct 2013  Â·  13Comments  Â·  Source: mozilla/pdf.js

Hi, I am unable to get my PDF displayed , It always stops at below warning and does not call call back functions for getPage. Not sure what am i missing here

[12:04:48.929] Warning: Unhandled rejection: TypeError: PDFJS.WorkerMessageHandler is undefined
WorkerTransport_setupFakeWorker@http://192.168.2.3:10080/CSEMobile/apps/services/preview/CSEMobileHybrid/common/1.0/default/resources/scripts/pdf/src/pdf.js:4358
pdfjsWrapper/WorkerTransport/<@http://192.168.2.3:10080/CSEMobile/apps/services/preview/CSEMobileHybrid/common/1.0/default/resources/scripts/pdf/src/pdf.js:4314
bind/<@http://192.168.2.3:10080/CSEMobile/apps/services/preview/CSEMobileHybrid/common/1.0/default/common/js/base.js:762
runHandlers@http://192.168.2.3:10080/CSEMobile/apps/services/preview/CSEMobileHybrid/common/1.0/default/resources/scripts/pdf/src/pdf.js:797
bind/<@http://192.168.2.3:10080/CSEMobile/apps/services/preview/CSEMobileHybrid/common/1.0/default/common/js/base.js:762

Most helpful comment

@maiorano84 did you set a worker?
Had the same issue right now and I solved with this
PDFJS.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';

There is a short explanation in the examples page

All 13 comments

It's difficult to tell from this description, but I assume that you are trying to integrate PDF.js in your own project.
If that is the case, please see: https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#wiki-custom, especially this part:

please prepare short well-documented example that demonstrate the problem and make it accessible online on your website, jsbin, etc.

Also, please provide more information regarding your configuration, such as: Operating System, Browser and other details that might be relevant to the issue.

Having the same issue (PDFJS.version = '0.8.613'; PDFJS.build = '54acf20';) running on Mac. Tried Safari, Chrome and Firefox. Error raises in everyone of them, if PDFJS.disableWorker = true. If disableWorker undefined or false, no output at all is given.

@negativalpha Is this still an issue? If so, please provide a link to the broken PDF file or provide more information on your custom implementation.

No response, closing as incomplete.

Reopening this, as I believe I'm running into a similar issue:

-- Live example --

[removed]


-- Console --

Warning: Setting up fake worker.
pdf.js?ver=3.8.16:8130 Uncaught TypeError: Cannot read property 'WorkerMessageHandler' of undefined
at pdf.js?ver=3.8.16:8130
at HTMLScriptElement.Util_loadScript.script.onload (pdf.js?ver=3.8.16:812)


-- Environment --

Server: MediaTemple DV - CentOS
OS: Mac OS X El Capitan
Browser: Chrome 55.0.2883.95 (64-bit)


-- Implementation --

jQuery(document).ready(function($){
    $(".portfolio_preview_container").on('DOMNodeInserted', function () {
        $("[data-canvas-pdf]").each(function(){
            var pdf = new CanvasPDF($(this).attr("data-canvas-pdf"));
        });
    });
});

var CanvasPDF = function(url){
    var pdfDoc = null,
        pageNum = 1,
        pageRendering = false,
        pageNumPending = null,
        scale = 0.8,
        canvas = document.getElementById('the-canvas'),
        ctx = canvas.getContext('2d');

    //.... Remainder is copied verbatim from /examples/learning/prevnext.html
};

-- Explanation --

The contents of each portfolio item is loaded through AJAX. I'm listening for a DOMNodeInserted event to trigger off the search for any elements containing the [data-canvas-pdf] attribute - the value of which is the URL path to the target PDF.

I hope this is enough information to go off of. I've been wrestling with this for about a good 5 hours, and I could use a fresh pair of eyes on it.

@maiorano84 did you set a worker?
Had the same issue right now and I solved with this
PDFJS.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';

There is a short explanation in the examples page

@rkpasia I hadn't seen those examples before. I'll take a look into that to see if that was my problem. +1 for the suggestion.

import pdfjs from 'pdfjs-dist'
pdfjs.disableWorker = true
pdfjs.workerSrc = ''

doesn't work

I'm also getting this same error. I believe @rkpasia is correct but I'm not sure what do do in my situation. What are you supposed to set "PDFJS.workerSrc" to when all my JS files are concatenated into one?

Maybe try to set the worker in another way, try to find the root object and set it manually.

I also had similar problem.

pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';

worked for me.

You should host the pdf.worker.js file yourself though instead of getting it from our website since that's a development build that constantly changes, so it's not recommended for stability.

Oh, I see. Okay, I will host the worker file in my server only. Thanks for
the suggestion.

On Sun, 25 Nov 2018 at 12:20 AM, Tim van der Meij notifications@github.com
wrote:

You should host the pdf.worker.js file yourself though instead of getting
it from our website since that's a development build that constantly
changes, so it's not recommended for stability.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/mozilla/pdf.js/issues/3754#issuecomment-441388015,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AYZQ6VhtS8gPZXReK1p9DnzKNXrcc7aGks5uyZUBgaJpZM4BDk20
.

>

Thank you!

With Regards,
Tamil Vendhan Kanagarasu

Was this page helpful?
0 / 5 - 0 ratings