javascriptjsonpdfpdf.jspdf-annotations

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


tried to load saved json from local storage using JSON.parse(localStorage.getItem("CanvaData"))

  ready() {
    console.log("Plugin initialized successfully");

    var arr = JSON.parse(localStorage.getItem("CanvaData"));
    console.log(arr)
    // localStorage.clear();
    pdf.loadFromJSON(arr)
  },

but as you can see it's throwing SyntaxError: Unexpected end of JSON input .

how to resolve this issue?


Solution

  • So after investigating for hours i found the issue that causes this.

    i saved the json into local storage as a single string

    localStorage.setItem('CanvaData', JSON.stringify(pdf.serializePdf()));
    

    now i changed it to save the data as json to local storage

    localStorage.setItem('CanvaData', pdf.serializePdf());
    

    after that i modified the load from json as the following:

    ready() {
        console.log("Plugin initialized successfully");
    
         var data123 = localStorage.getItem('CanvaData');
         pdf.loadFromJSON(JSON.parse(data123))
      },
    

    Fixed.