1、直接调用openOFDBaseViewer ,用于超过100页的,1页也可以,有加载动画
onWebassemblyRuntimeInitialized(() => {
openOFDBaseViewer(file, '6wsz1zH2NHnRKuvH', this.$refs['ofd-continer'], this.screenWidth)
})
parseOfdDocument({
// ofd写入文件地址
ofd: file,
secret: '6wsz1zH2NHnRKuvH',
success: async(res) => {
// 输出ofd每页的div
// const screenWidth = 300
const divs = await renderOfd(screenWidth, res[0])
const contentDiv = this.$refs['ofd-continer']//容器
contentDiv.innerHTML = ''
for (const div of divs) {
// div.style.margin = 'auto'
contentDiv.appendChild(div)
}
},
fail(error) {
console.log(error)
}
})
import { onWebassemblyRuntimeInitialized, parseOfdDocument, renderOfd, openOFDBaseViewer } from 'ofd.js'
// import * as M from 'ofd.js'
// console.log(M)
<template>
<cafe-ofd ref="ofd" :file-path="file" @on-success="load" @on-scroll="scroll">
<div slot="header">
<input ref="file" type="file" class="hidden" accept=".ofd" @change="fileChanged">
</div>
<div slot="footer">
<button @click="plus">放大</button>
<button @click="minus">缩小</button>
<button :disabled="currentNum <= 1" @click="pre">上一页</button>
<input v-model.number="currentNum" type="number" :min="1" :max="pageNum" @change="pageChange(currentNum)">
<button :disabled="currentNum >= pageNum" @click="next">下一页</button>
<button @click="print">打印</button>
</div>
</cafe-ofd>
</template>
<script>
import cafeOfd from 'cafe-ofd'
import 'cafe-ofd/package/index.css'
// console.log(cafeOfd)
// Vue.use(cafeOfd)
export default {
name: 'ofdApp',
components: { cafeOfd: cafeOfd.cafeOfd },
data() {
// 这里存放数据
return {
currentNum: null,
file: null,
pageNum: null
}
},
methods: {
load(val) {
this.pageNum = val
},
fileChanged() {
this.file = this.$refs.file.files[0]
},
plus() {
this.$refs.ofd.scale(50)
},
minus() {
this.$refs.ofd.scale(-50)
},
next() {
this.$refs.ofd.nextPage()
},
pre() {
this.$refs.ofd.prePage()
},
pageChange(val) {
this.$refs.ofd.goToPage(val)
},
print() {
this.$refs.ofd.printFile()
},
scroll(val) {
this.currentNum = val
}
}
}
</script>
<style>
@media print {
html,
body,
#app {
height: auto;
overflow: auto;
}
}
</style>