目前方案采用wasm实现ofd解析、渲染、验签,不支持IE
examples已增加原生js、reactjs的demo
npm i ofd.js
目前可以通过 unpkg.com/ofd.js 获取到最新版本的资源,在页面上引入 js 文件即可开始使用。
html引用js文件
<script type="text/javascript" src="./OfdParser.js"></script>
<script type="text/javascript" src="./FreetypeKit.js"></script>
<script src="https://unpkg.com/ofd.js"></script>
<script type="text/javascript">
ofd.onWebassemblyRuntimeInitialized(()=>{
console.log(ofd)
})
</script>
onWebassemblyRuntimeInitialized(()=>{
//do something
})
ofdFile为OFD文件。支持File或者ArrayBuffer
parseOfdDocument({
ofd: ofdFile,
success(res) {
console.log(res)
}
})
ofdData为解析ofd文件接口返回的OFD对象
documentIndex为ofd文档中document的索引,默认从0开始
getOFDPageCount(ofdData, documentIndex)
ofdData为解析ofd文件接口返回的OFD对象
documentIndex为ofd文档中document的索引,默认从0开始
pageIndex为ofd文档中页码,默认从0开始
pageWidth(ofdData, documentIndex, pageIndex)
ofdData为解析ofd文件接口返回的OFD对象
documentIndex为ofd文档中document的索引,默认从0开始
pageIndex为ofd文档中页码,默认从0开始
pageHeight(ofdData, documentIndex, pageIndex)
dpi---对应的dpi值,默认是96
setPageDPI(dpi)
ofdData为解析ofd文件接口返回的OFD对象
documentIndex为ofd文档中document的索引,默认从0开始
renderOfd(ofdData, documentIndex)
pageDiv为html中div容器
ofdData为解析ofd文件接口返回的OFD对象
documentIndex为ofd文档中document的索引,默认从0开始
pageIndex为ofd文档中页码,默认从0开始
renderOfdByIndex(pageDiv, ofdData, documentIndex, pageIndex)
html需要添加一个id为OfdView的div容器,其中overflow必须设置为auto,height必须有值,否则不会自动渲染后面的页面
<div id="OfdView" style="overflow:auto;height:1000px"></div>
js方法
ofdFile为OFD文件。支持File或者ArrayBuffer
openOfdView(ofdFile)
如需获取帮助可以扫码加微信或者知识星球
项目获得 Star曲线