pdf2json icon indicating copy to clipboard operation
pdf2json copied to clipboard

Running on Electron "Uncaught Error: No PDFJS.workerSrc specified"

Open whitef0x0 opened this issue 8 years ago • 12 comments

For some reason when I run pdf2json on my electron app I get "Uncaught Error: No PDFJS.workerSrc specified".

FYI: I tried setting workerSrc to pdf.worker.js but that won't solve it. It just brings up another error,

whitef0x0 avatar Jun 05 '16 06:06 whitef0x0

@modesty

whitef0x0 avatar Jun 07 '16 06:06 whitef0x0

how did you run pdf2json? if you run it via cmd line, or as a web service, this error should not occur.

modesty avatar Jul 02 '16 23:07 modesty

@modesty I ran in an electron app.

whitef0x0 avatar Jul 05 '16 01:07 whitef0x0

pdj2json is designed to run outside browser, and never tested with embedded browser (as in electron framework). 3 options here:

  • invoke cmd line to run pdf2json from your app
  • set globalScope.PDFJS.disableWorker to be true
  • set PDFJS.workerSrc = Worker

modesty avatar Jul 05 '16 18:07 modesty

@whitef0x0 @modesty It turns out that I have the same problem too. Any luck on running pdf2json in electron? Thanks...

wilsonchandra avatar Nov 09 '16 02:11 wilsonchandra

It works when you run it in the main process and not in any of the rendering process, and use the remote api to exchange data between them.

lanwin avatar Dec 04 '16 08:12 lanwin

@lanwin Thanks for your heads up. That works for me too...

wilsonchandra avatar Jul 14 '17 07:07 wilsonchandra

It should be possible to require it in a rendering process by: require('electron').remote.require(...)

parzel avatar Jun 24 '18 21:06 parzel

@parzel Thanks for the explanation. I used it that way too...

wilsonchandra avatar Jun 26 '18 11:06 wilsonchandra

using let PDFParser = require('electron').remote.require('pdf2json') instead of let PDFParser = require('pdf2json')

worked for me. Thank you!

suparpat avatar Apr 03 '19 04:04 suparpat

@suparpat - can you please tell, what should I do to get the same PDFParser object in nwjs app? I'm getting the same issue, most probably it'll be the same solution. However, I'm unable to load pdf2json module correctly in nwjs app.

sunilrebel avatar Jul 23 '20 09:07 sunilrebel

It worked for me during development with electron:serve, after bundling the program with electron:build, opening the executable would cause the module not being found.

I did the correct way and moved my code to the main proccess.

samuel-mrodrigues avatar Aug 22 '22 18:08 samuel-mrodrigues