RavishaHesh / PDFJsAnnotations

Wrapper for PDF JS to add annotations
MIT License
322 stars 98 forks source link

pdf.loadFromJSON(serializedJSON) not working #53

Open janlord01 opened 2 years ago

janlord01 commented 2 years ago

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

RavishaHesh commented 2 years ago

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

janlord01 commented 2 years ago

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.

str commented 2 years ago

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

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)

any solution?

str commented 2 years ago

@khaledmndev and can you post your data1 value?

khaledmndev commented 2 years ago

@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

str commented 2 years ago

@khaledmndev and what error message do you get?

khaledmndev commented 2 years ago

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

str commented 2 years ago

@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.

khaledmndev commented 2 years ago

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