Code Monkey home page Code Monkey logo

ofd.js's Introduction

ofd.js

- license

目前方案采用wasm实现ofd解析、渲染、验签,不支持IE

examples已增加原生js、reactjs的demo

效果: 示例

体验地址

pc安装包

Usage with npm

npm i ofd.js

Usage with CDN

目前可以通过 unpkg.com/ofd.js 获取到最新版本的资源,在页面上引入 js 文件即可开始使用。

html引用js文件
<script type="text/javascript" src="./OfdParser.js"></script>
<script src="https://unpkg.com/ofd.js"></script>

<script type="text/javascript">
    ofd.onWebassemblyRuntimeInitialized(()=>{
        console.log(ofd)
    })  
</script>

相关接口说明

webassembly加载回调

onWebassemblyRuntimeInitialized(()=>{
//do something
})

解析OFD文件

ofdFile为OFD文件。支持File、ArrayBuffer及url
secret

parseOfdDocument({
        ofd: ofdFile,
        secret: '6wsz1zH2NHnRKuvH',
        success(res) {
            console.log(res)
        }
    })

获取OFD文档页数

ofdData为解析ofd文件接口返回的OFD对象
documentIndex为ofd文档中document的索引,默认从0开始

getOFDPageCount(ofdData, documentIndex)

获取OFD文档对应页的页宽

ofdData为解析ofd文件接口返回的OFD对象
documentIndex为ofd文档中document的索引,默认从0开始
pageIndex为ofd文档中页码,默认从0开始

pageWidth(ofdData, documentIndex, pageIndex)

获取OFD文档对应页的页高

ofdData为解析ofd文件接口返回的OFD对象
documentIndex为ofd文档中document的索引,默认从0开始
pageIndex为ofd文档中页码,默认从0开始

pageHeight(ofdData, documentIndex, pageIndex)

一次性渲染OFD对应文档的所有页,适合页数少

ofdData为解析ofd文件接口返回的OFD对象
documentIndex为ofd文档中document的索引,默认从0开始

renderOfd(ofdData, documentIndex, width)

渲染OFD对应文档的对应页

pageDiv为html中div容器
ofdData为解析ofd文件接口返回的OFD对象
documentIndex为ofd文档中document的索引,默认从0开始
pageIndex为ofd文档中页码,默认从0开始

renderOfdByIndex(pageDiv, ofdData, documentIndex, pageIndex, width)

打开一个基础的内置ofdview。适合打开大于100页的文档,具体看examples中的html例子

html需要添加一个id为OfdView的div容器,其中overflow必须设置为auto,height必须有值,否则不会自动渲染后面的页面

<div id="OfdView" style="overflow:auto;height:1000px"></div>

js方法

ofdFile为OFD文件。支持File、ArrayBuffer及url

openOfdBaseViewer(ofdFile)

获取帮助

如需获取帮助可以扫码加微信或者知识星球

示例

示例

微信小程序体验OFD

示例

ofd推荐项目

OFD Reader & Writer

ofd.android

项目关注度

项目获得 Star曲线

Stargazers over time

ofd.js's People

Contributors

dltech21 avatar roy19831015 avatar godlift avatar iandjava avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.