PDFJsAnnotations icon indicating copy to clipboard operation
PDFJsAnnotations copied to clipboard

pdf.loadFromJSON(serializedJSON) not working

Open janlord01 opened this issue 4 years ago • 10 comments

Tried to load pdf.loadFromJSON(serializedJSON) but its not working. Any help please? Thanks

janlord01 avatar Jan 17 '22 09:01 janlord01

Are there any errors in the browser's dev tool console? like JSON parse errors

RavishaHesh avatar Jan 17 '22 09:01 RavishaHesh

Are there any errors in the browser's dev tool console? like JSON parse errors

no errors on ready(), but when I console log it, it outputs undefined.

janlord01 avatar Jan 17 '22 10:01 janlord01

@janlord01 could you please paste your code to better understand your issue?

str avatar Jan 31 '22 19:01 str

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)

any solution?

khaledmndev avatar Mar 30 '22 16:03 khaledmndev

@khaledmndev and can you post your data1 value?

str avatar Mar 30 '22 17:03 str

@khaledmndev and can you post your data1 value?

sure, i used console.log(data1) if you that i you wanted:

here's a link for the value stored in a txt file, since the value and size is too big (sorry can't paste it here): https://mega.nz/file/q9ZmxRZb#qJPj3mB8MQzG34UWf53zPRbO960XsdVnRdS9RzluGeY

khaledmndev avatar Mar 30 '22 17:03 khaledmndev

@khaledmndev and what error message do you get?

str avatar Mar 30 '22 17:03 str

@str 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)

khaledmndev avatar Mar 30 '22 17:03 khaledmndev

@khaledmndev as you can see, the error says it was not able to parse the JSON value (1.5MB string length). It may be because of the length of the background fields in the canvas. I suggest you to try without the backgrounds

If you still get any errors, I suggest you to open a new issue with that error message.

str avatar Mar 30 '22 17:03 str

@str still no luck i've tried with only drawing with pen! i'll open a new issue..

by the way i tried pasting the json value data into pdf.loadFromJSON("here"), and it worked! thanks for helping anyways :)

khaledmndev avatar Mar 30 '22 17:03 khaledmndev