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: Image is not defined #9518

Closed
Ayrtonalec opened this issue Feb 28, 2018 · 4 comments
Closed

ReferenceError: Image is not defined #9518

Ayrtonalec opened this issue Feb 28, 2018 · 4 comments

Comments

@Ayrtonalec
Copy link

Ayrtonalec commented Feb 28, 2018

I'm getting the following error, no matter what PDF I use. (I also get a lot of Document is not defined)

Anyone who has any idea why this occurs and preferably how to solve this?
Thanks for taking your time to read this and possibly helping me out!

Relevant information:

  • using NodeJs
  • Already gathered a lot of data through optree but none relevant to images
  • Goal is to get base64 of the images within the pdf and use that data in my (JSON) api
  • Used PDF:
    flyer wijk.pdf
(node:23463) ReferenceError: Image is not defined
    at loadJpegStream (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1341:17)
    at Object.transportObj (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:4296:38)
    at LoopbackPort.MessageHandler._onComObjOnMessage (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1039:19)
    at LoopbackPort.<anonymous> (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3818:20)
    at Array.forEach (native)
    at /home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3817:27
    at process._tickCallback (internal/process/next_tick.js:109:7)
(node:23463) ReferenceError: Image is not defined
    at loadJpegStream (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1341:17)
    at Object.transportObj (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:4296:38)
    at LoopbackPort.MessageHandler._onComObjOnMessage (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1039:19)
    at LoopbackPort.<anonymous> (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3818:20)
    at Array.forEach (native)
    at /home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3817:27
    at process._tickCallback (internal/process/next_tick.js:109:7)

The relevant code is:

function loadJpegStream(id, imageUrl, objs) {
  var img = new Image();    // <- here is where the error links to, original pdfjs file not edited or anything.
  img.onload = function loadJpegStream_onloadClosure() {
    objs.resolve(id, img);
  };

The Document is not defined error (Higher up in the console):

Warning: Unable to decode image: UnknownErrorException: "document" is not defined.
(node:1499) ReferenceError: document is not defined
    at Object.fontLoaderInsertRule [as insertRule] (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:12749:42)
    at Object.fontLoaderBind [as bind] (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:12807:16)
    at Object.transportObj (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:4273:29)
    at LoopbackPort.MessageHandler._onComObjOnMessage (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1039:19)
    at LoopbackPort.<anonymous> (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3819:20)
    at Array.forEach (native)
    at /home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3818:27
    at process._tickCallback (internal/process/next_tick.js:109:7)
(node:1499) ReferenceError: document is not defined
    at Object.fontLoaderInsertRule [as insertRule] (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:12749:42)
    at Object.fontLoaderBind [as bind] (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:12807:16)
    at Object.transportObj (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:4273:29)
    at LoopbackPort.MessageHandler._onComObjOnMessage (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1039:19)
    at LoopbackPort.<anonymous> (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3819:20)
    at Array.forEach (native)
    at /home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3818:27
    at process._tickCallback (internal/process/next_tick.js:109:7)
(node:1499) ReferenceError: document is not defined
    at Object.fontLoaderInsertRule [as insertRule] (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:12749:42)
    at Object.fontLoaderBind [as bind] (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:12807:16)
    at Object.transportObj (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:4273:29)
    at LoopbackPort.MessageHandler._onComObjOnMessage (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1039:19)
    at LoopbackPort.<anonymous> (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3819:20)
    at Array.forEach (native)
    at /home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3818:27
    at process._tickCallback (internal/process/next_tick.js:109:7)
(node:1499) ReferenceError: document is not defined
    at Object.fontLoaderInsertRule [as insertRule] (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:12749:42)
    at Object.fontLoaderBind [as bind] (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:12807:16)
    at Object.transportObj (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:4273:29)
    at LoopbackPort.MessageHandler._onComObjOnMessage (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1039:19)
    at LoopbackPort.<anonymous> (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3819:20)
    at Array.forEach (native)
    at /home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3818:27
    at process._tickCallback (internal/process/next_tick.js:109:7)
(node:1499) ReferenceError: Image is not defined
    at loadJpegStream (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1342:17)
    at Object.transportObj (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:4297:38)
    at LoopbackPort.MessageHandler._onComObjOnMessage (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1039:19)
    at LoopbackPort.<anonymous> (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3819:20)
    at Array.forEach (native)
    at /home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3818:27
    at process._tickCallback (internal/process/next_tick.js:109:7)
(node:1499) ReferenceError: document is not defined
    at Object.fontLoaderInsertRule [as insertRule] (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:12749:42)
    at Object.fontLoaderBind [as bind] (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:12807:16)
    at Object.transportObj (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:4273:29)
    at LoopbackPort.MessageHandler._onComObjOnMessage (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1039:19)
    at LoopbackPort.<anonymous> (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3819:20)
    at Array.forEach (native)
    at /home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3818:27
    at process._tickCallback (internal/process/next_tick.js:109:7)
(node:1499) ReferenceError: Image is not defined
    at loadJpegStream (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1342:17)
    at Object.transportObj (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:4297:38)
    at LoopbackPort.MessageHandler._onComObjOnMessage (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:1039:19)
    at LoopbackPort.<anonymous> (/home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3819:20)
    at Array.forEach (native)
    at /home/ec2-user/environment/pdf-parser/node_modules/pdfjs-dist/build/pdf.js:3818:27
    at process._tickCallback (internal/process/next_tick.js:109:7)
@Snuffleupagus
Copy link
Collaborator

Closing as duplicate of issue #9373.

@Ayrtonalec
Copy link
Author

Ayrtonalec commented Feb 28, 2018

@Snuffleupagus That one is over a month old, doesn't have answers, isn't going to get any answers anytime soon and doesn't have the document isn't defined error which is a part of my error. Don't close this one because it'd result me (and possibly others) into having the issue without any results. If you want to close it because it'd be arguably a duplicate, give it at the very least a couple of hours to see whether someone can help or to help raise light to this apparently recent occurring error.

@Snuffleupagus
Copy link
Collaborator

That one is over a month old, doesn't have answers, isn't going to get any answers anytime soon

It has an answer now. Besides, I'm not sure on what grounds you can reasonably state with any certainty that a question won't get an answer just because it wasn't given immediately. (Please keep in mind that this is not paid support, but rather volunteers helping out in their spare time.)

doesn't have the document isn't defined error which is a part of my error.

That part would be a duplicate of issue #8489. See also issue #7929, where #7929 (comment) provides a workaround.


Finally, please note that closing duplicates is commonplace in (open source) bug trackers. This makes it easier to navigate/find issues, and ensures that relevant discussions happens in one place rather than being spread out.

@Ayrtonalec
Copy link
Author

@Snuffleupagus Alright, I appreciate the answer and helping me (and probably the other guy as well) out a bit. I just realized that my previous answer felt a tiny bit rude and I'm sorry if you felt that way about it as well, I'd like to apologize for that. Again, thank you for the answer.

-Rick

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

No branches or pull requests

2 participants