Webodf display odf from bytes

浪尽此生 提交于 2019-12-13 18:20:01

问题


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

Currently using:

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:


Yes, It is possible to read an odt file from byte Array and then load it in webodf editor.

  1. To do so ,you will have to use javascript blob objects to construct a file from a byte array(desired file in bytes format).

  2. Then you can get a temporary url for that blob object which is very similar to a file itself.The 'url' is temporary url created and stored in browser.

  3. Once you have the url for your file ( bytes => blob => getUrl ) then you can easily load the file in your webodf editor using '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



回答2:


We are using WebAPIs to push out the file stream. Seems you could setup a shim service to much the same? Else there might be some info to glean form the local editor (as it must do an upload of some form)?

Which I could help more, but I'm new to WebODF myself and thus far it's been a bit... obtuse ;)



来源:https://stackoverflow.com/questions/21584759/webodf-display-odf-from-bytes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!