Webodf displays odf from bytes

Is it possible for webodf to read the odf / odt file from its bytes? instead of a url?

Currently used:

var odfelement = document.getElementById("odf");
var odfcanvas = new odf.OdfCanvas(odfelement);

odfcanvas.load("url/to/file.odt");

      

and would like something like

odfcanvas.loadFromBytes(bytes);

      

+1


source to share


2 answers


Yes, it is possible to read an odt file from a byte array and then load it into the webodf editor.

  • To do this, you will need to use javascript blob objects to create a file from a byte array (desired file in byte format).

  • Then you can get the temporary url for that blob object, which is very similar to the file itself. "url" is a temporary url created and saved in the browser.

  • Once you have the url for your file (bytes => blob => getUrl), you can easily load the file in your webodf editor using the "openDocumentFromUrl" function.




  var file = new Blob([data], {type: mimeType});
  // data  => your bytes file
  // mimeType => the mimetype of file(odt : application/vnd.oasis.opendocument.text)

  var myUrl= URL.createObjectURL(file);
  // get the temorary url from blob object.

  editor.openDocumentFromUrl(myUrl, function(){});

  // editor is the active webodf context object which you get when webodf context is created

      

+1


source


We use WebAPI to preempt the file stream. It seems like you could customize your sewing service in much the same way? Also, could there be some information to get the local editor form (since it has to load some form)?



Which I could help more, but I'm new to WebODF myself and so far this has been a bit ... obtuse;)

0


source







All Articles