RavishaHesh / PDFJsAnnotations

Wrapper for PDF JS to add annotations
MIT License
333 stars 99 forks source link

Uncaught (in promise) SyntaxError: Unexpected end of JSON input #56

Closed khaledmndev closed 2 years ago

khaledmndev commented 2 years ago

i'm having an issue while retrieving json data from the storage after parsing it

here's my code:

 var data1 = JSON.parse(localStorage.getItem('CanvaData'));
 pdf.loadFromJSON(data1)

Error:

Uncaught (in promise) SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at i.loadFromJSON (fabric.min.js:1:131008)
at i. (pdfannotate.js:286:14)
at Function.each (jquery.min.js:2:2976)
at PDFAnnotate.loadFromJSON (pdfannotate.js:284:4)
at Object.ready (script.js:15:13)
at HTMLCanvasElement. (pdfannotate.js:87:13)
at Function.each (jquery.min.js:2:2976)
at S.fn.init.each (jquery.min.js:2:1454)
at PDFAnnotate.initFabric (pdfannotate.js:60:15)

and it's working perfectly when i manually paste the json data into pdf.loadFromJSON([here])

RavishaHesh commented 2 years ago

I don't think JSON.parse is necessary if you save it in the local storage. can you try without it?

khaledmndev commented 2 years ago

I don't think JSON.parse is necessary if you save it in the local storage. can you try without it?

this one worked perfectly, thanks, just a question, is there anyway to integrate this with dflipjs library? it also uses PDF.js

RavishaHesh commented 2 years ago

it might be possible, but that's not going to be easy. you have hack into the plugin's code

khaledmndev commented 2 years ago

@RavishaHesh alright thanks for helping me, but just one annoying question, is there a way to save the canvas without the psd images to json? To reduce the of the json output, this way i can load the psd file alone and import the canvas from the json..