Webodf从字节显示odf [英] Webodf display odf from bytes

查看:188
本文介绍了Webodf从字节显示odf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

webodf是否可以从其字节读取odf/odt文件?而不是网址?

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

当前使用:

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

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

,并且想要类似的东西

odfcanvas.loadFromBytes(bytes);

推荐答案

是的,可以从字节数组读取odt文件,然后将其加载到webodf编辑器中.

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

  1. 为此,您将必须使用javascript blob对象从字节数组(所需的字节格式文件)中构建文件.

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

然后您可以为该blob对象获得一个临时URL,该临时URL与文件本身非常相似.'url'是创建并存储在浏览器中的临时URL.

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.

一旦有了文件的URL(字节=> blob => getUrl),便可以使用" openDocumentFromUrl "功能轻松地在webodf编辑器中加载文件.

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

这篇关于Webodf从字节显示odf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆