我已经实现了pdf预览,但是我们要求实现所有文本文件的预览。
请问一下有什么好的office文件预览插件或者好方法没有,或者是前端能够实现文件转pdf的方法(我希望得到这类方法)。(拒绝网上说的利用在线office预览的功能)
<template>
<div class="pdf" v-show="fileType === 'pdf'">
<p class="arrow">
<span @click="changePdfPage(0)" class="turn" :class="{grey: currentPage==1}">Preview</span>
{{ currentPage }} / {{ pageCount }}
<span @click="changePdfPage(1)" class="turn" :class="{grey: currentPage==pageCount}">Next</span>
</p>
<pdf :src="src" :page="currentPage"
@num-pages="pageCount=$event"
@page-loaded="currentPage=$event"
@loaded="loadPdfHandler">
</pdf>
</div>
</template>
<script>
import pdf from 'vue-pdf'
export default {
components: {
pdf
},
data () {
return {
currentPage: 0,
pageCount: 0,
fileType: 'pdf',
src: ''
}
},
created () {
this.$bus.on('startPdfPreview', (val) => {
this.src = val
})
// this.src = pdf.createLoadingTask(this.src)
},
methods: {
changePdfPage (val) {
if (val === 0 && this.currentPage > 1) {
this.currentPage--
}
if (val === 1 && this.currentPage < this.pageCount) {
this.currentPage++
}
},
loadPdfHandler (e) {
this.currentPage = 1
}
}
}
</script>
<style>
span {
color: white;
}
</style>
我们做项目 前端预览文件 都是后端转的 前端自己做文件预览 就是坑。
https://cloud.e-iceblue.cn/welcome.html
前端预览pdf可以借助pdf.js
但是其它格式必须借助服务器,流行的是flashpaper以及虚拟打印机转图片。
可以让后端吧办公类文件转成pdf 预览, 前端在线预览办公软件 都要借助服务
docx预览,npm地址:https://www.npmjs.com/package/docx-preview
还有这个npm地址:https://www.npmjs.com/package/cordova-plugin-preview-any-file
开源的在线文档预览项目,.ppt,.pptx,.doc,.docx,.xls,.xlsx,.pdf文件都可以,我试过了
https://github.com/kekingcn/file-online-preview.git
可以试试转图片或者PDF的形式,可以时候这个在线预览模式
https://usdoc.cn/office.html