pdf2svg icon indicating copy to clipboard operation
pdf2svg copied to clipboard

Image is not defined

Open NHQ opened this issue 11 years ago • 7 comments

I tried running pdf2js on this large pdf, which can be found http://bibliothequekandinsky.centrepompidou.fr/imagesbk/FondsKandinskyL498/M5050_X0031_LKA_L498.pdf, via http://monoskop.org/log/?p=11943 Got the following error. The svg dump got about 13 pages in.

Warning: Setting up fake worker.
# Document Loaded
Number of Pages: 234


Error: [object Object]
    at error (/home/johnny/projects/pdf2svg/js/pdf.combined.js:252:15)
    at Object.transportError (/home/johnny/projects/pdf2svg/js/pdf.combined.js:2520:11)
    at Object.messageHandlerComObjOnMessage [as onmessage] (/home/johnny/projects/pdf2svg/js/pdf.combined.js:1512:19)
    at Object.WorkerTransport_postMessage [as postMessage] (/home/johnny/projects/pdf2svg/js/pdf.combined.js:2332:24)
    at Object.MessageHandler.postMessage (/home/johnny/projects/pdf2svg/js/pdf.combined.js:1576:19)
    at Object.messageHandlerSend [as send] (/home/johnny/projects/pdf2svg/js/pdf.combined.js:1539:10)
    at Object.onReject (/home/johnny/projects/pdf2svg/js/pdf.combined.js:39321:19)
    at Object.runHandlers (/home/johnny/projects/pdf2svg/js/pdf.combined.js:1149:35)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
Warning: Unsupported feature "unknown"
Warning: Unhandled rejection: ReferenceError: Image is not defined
ReferenceError: Image is not defined
    at loadJpegStream (/home/johnny/projects/pdf2svg/js/pdf.combined.js:1582:17)
    at Object.transportObj (/home/johnny/projects/pdf2svg/js/pdf.combined.js:2483:13)
    at Object.messageHandlerComObjOnMessage [as onmessage] (/home/johnny/projects/pdf2svg/js/pdf.combined.js:1512:19)
    at Object.WorkerTransport_postMessage [as postMessage] (/home/johnny/projects/pdf2svg/js/pdf.combined.js:2332:24)
    at Object.MessageHandler.postMessage (/home/johnny/projects/pdf2svg/js/pdf.combined.js:1576:19)
    at Object.messageHandlerSend [as send] (/home/johnny/projects/pdf2svg/js/pdf.combined.js:1539:10)
    at Object.PartialEvaluator_buildPaintImageXObject [as buildPaintImageXObject] (/home/johnny/projects/pdf2svg/js/pdf.combined.js:16543:22)
    at Object.next (/home/johnny/projects/pdf2svg/js/pdf.combined.js:16987:24)
    at Object.Promise (/home/johnny/projects/pdf2svg/js/pdf.combined.js:1224:16)
    at Object.PartialEvaluator_getOperatorList [as getOperatorList] (/home/johnny/projects/pdf2svg/js/pdf.combined.js:16941:14)

NHQ avatar Aug 19 '14 18:08 NHQ

Removing if (!softMask && !mask && image instanceof JpegStream && image.isNativelySupported(this.xref, resources)) { ... } block form pdf.combined.js might fix the issue.

yurydelendik avatar Aug 19 '14 19:08 yurydelendik

This is related to pullrequest #3

bmvakili avatar Aug 19 '14 20:08 bmvakili

@bmvakili pdf.js has its own embedded jpeg decoder, the change I mentioned above removes the optimization to use decoder for the web browser

yurydelendik avatar Aug 19 '14 20:08 yurydelendik

@yurydelendik hi, thanks; though it doesn't even get there. Error is thrown on the following line: 1582: var img = new Image();

See this stackoverflow for more details; http://stackoverflow.com/questions/9548074/nodejs-how-to-add-image-data-from-file-into-canvas

If "image" not defined, that line won't reach; e.g. 16542: image.isNativelySupported(this.xref, resources)) {

bmvakili avatar Aug 19 '14 21:08 bmvakili

@bmvakili there is another instance of it in handleImageData near if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) { ... }, sorry

yurydelendik avatar Aug 19 '14 21:08 yurydelendik

@yurydelendik yep, that's still way down in the processing. I actually tested pull request; with that change it will work; won't throw error.

bmvakili avatar Aug 19 '14 21:08 bmvakili

@bmvakili I don't think adding a new library is a good idea. It adds more overhead. Also, @yurydelendik 's fix works fine, for now.

pramodhkp avatar Aug 20 '14 17:08 pramodhkp