当前位置: 首页 > wzjs >正文

清远佛冈住房和城乡建设局网站上热门最火标题

清远佛冈住房和城乡建设局网站,上热门最火标题,大型手游网络游戏排行榜,东莞网站关键词优化收费今天一天对当前可用的pdf预览插件做了测试,主要需求是只能预览不能下载,但对于前端来说,没有绝对的禁止,这里只罗列实现方式。 目前采用vue3版本为:3.2.37 iframevue-officepdfjs-dist iframe 先说最简单的&#xf…

今天一天对当前可用的pdf预览插件做了测试,主要需求是只能预览不能下载,但对于前端来说,没有绝对的禁止,这里只罗列实现方式。
目前采用vue3版本为:3.2.37

  1. iframe
  2. vue-office
  3. pdfjs-dist

iframe

先说最简单的,iframe可以直接展示pdf文件,所以如果不作禁止预览等操作,iframe是最合适的。

    <el-dialogv-model="previewOtherUpload"reset-drag-positiondraggablesticky:title="_options.imgName || '详情'"footer-hideclass-name="vertical-center-modal"><div@contextmenu.preventstyle="user-select: none;"><iframeref="iframe":src="`${modelValue}#toolbar=0`"width="100%"height="600px"@load="onIframeLoad"></iframe></div></el-dialog><script setup>
const modelValue = ref('https://501351981.github.io/vue-office/examples/dist/static/test-files/test.pdf')
let previewOtherUpload = ref(false);
const iframe = ref(null)const clickShow = () => {previewOtherUpload.value = true;
}// 尝试在iframe加载完毕后,进行右键禁用,但实际需要通过postmessage来处理,所以这里无实际用处
const onIframeLoad = () => {try {console.log('iframe 已加载', iframe.value.contentWindow.window);if (iframe.value.contentWindow.document) {iframe.value.contentWindow.document.addEventListener('contextmenu', (e) => e.preventDefault());}} catch (error) {console.error('无法访问 iframe 内容:', error);}
}
</script>

在这里插入图片描述

vue-office

vue-office-gitcode地址

安装
#docx文档预览组件
npm install @vue-office/docx vue-demi@0.14.6#excel文档预览组件
npm install @vue-office/excel vue-demi@0.14.6#pdf文档预览组件
npm install @vue-office/pdf vue-demi@0.14.6#pptx文档预览组件
npm install @vue-office/pptx vue-demi@0.14.6如果是vue2.6版本或以下还需要额外安装 @vue/composition-api
npm install @vue/composition-api

我们如果只预览pdf,则安装 npm install @vue-office/pdf vue-demi@0.14.6

    <el-dialogv-model="previewOtherUpload"reset-drag-positiondraggablesticky:title="_options.imgName || '详情'"footer-hideclass-name="vertical-center-modal"><div@contextmenu.preventstyle="user-select: none;"><VueOfficePdf:src="modelValue"/></div></el-dialog><script setup>
import VueOfficePdf from '@vue-office/pdf'
const modelValue = ref('https://501351981.github.io/vue-office/examples/dist/static/test-files/test.pdf')
let previewOtherUpload = ref(false);const clickShow = () => {previewOtherUpload.value = true;
}
</script>

在这里插入图片描述

pdfjs-dist

这是目前最麻烦的一个插件,一定先确定下载的版本"pdfjs-dist": “2.16.105”,我用的是这个,否则下面的workerSrc设置会有问题。

  <el-dialogv-model="previewOtherUpload"reset-drag-positiondraggablesticky:title="_options.imgName || '详情'"footer-hideclass-name="vertical-center-modal"><div id="pdf-view"@contextmenu.preventstyle="user-select: none;"><canvas v-for="page in state.pdfPages" :key="page" id="pdfCanvas" /><div id="text-view"></div></div></el-dialog><script setup>
import { computed, reactive, ref, watch, nextTick } from "vue";
import * as pdfjsViewer from 'pdfjs-dist/web/pdf_viewer.js'
import 'pdfjs-dist/web/pdf_viewer.css'
import * as PDF from 'pdfjs-dist'
// 设置 pdf.worker.js 路径
PDF.GlobalWorkerOptions.workerSrc = '../../../node_modules/pdfjs-dist/build/pdf.worker.js';
let pdfDoc = null;const modelValue = ref('https://501351981.github.io/vue-office/examples/dist/static/test-files/test.pdf')
let previewOtherUpload = ref(false);const clickShow = () => {loadFile(modelValue)previewOtherUpload.value = true;
}const loadFile = (url) => {PDF.getDocument({url,cMapUrl: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@2.16.105/cmaps/',cMapPacked: true,}).promise.then((pdf) => {pdfDoc = pdf// 获取pdf文件总页数state.pdfPages = pdf.numPagesnextTick(() => {renderPage(1) // 从第一页开始渲染})})
}
const renderPage = (num) => {pdfDoc.getPage(num).then((page) => {const canvas = document.getElementById('pdfCanvas')const ctx = canvas.getContext('2d')const viewport = page.getViewport({ scale: state.pdfScale })canvas.width = viewport.widthcanvas.height = viewport.heightconst renderContext = {canvasContext: ctx,viewport}page.render(renderContext)})
}
</script>

插件样式也不好调整,不推荐。

总结:
最后还是使用了第二种方式,作为禁止下载的展示。

http://www.dtcms.com/wzjs/53900.html

相关文章:

  • 优享微信网站建设google关键词
  • 暴雪手游怎样优化网络
  • 网站的建设好处国内能用的搜索引擎
  • 网站如何在百度百度如何推广广告
  • 北京住房保障建设投资中心网站网站排行查询
  • 做网站要多少钱电商网页制作教程
  • 中国建设银行支付网站网络营销最火的案例
  • 佛山市新城开发建设有限公司网站品牌营销策略
  • 芜湖做网站哪个公司好百度搜索广告怎么投放
  • 十大行情软件网站下载谷歌浏览器下载app
  • 滕州个人兼职做网站百度关键词关键词大全
  • 如何建设网站的外接 以及在增加外接的时应当注意什么seo外包公司报价
  • 张家港网站开发培训百度手游app下载
  • 天津塘沽爆炸事件seo在线优化
  • 网站建设使用的什么软件爱站在线关键词挖掘
  • 兰州市做网站建设的公司湖南网站推广公司
  • 最新企业网站营销型企业网站
  • 淘宝客网站如何做排名百度推送
  • 新疆建设职业培训中心网站今日头条热榜
  • 设计建设网站公司哪家好百度天眼查
  • 消防做设计有什么网站网络整合营销4i原则是指
  • 济南外贸网站建设百度网盘资源搜索引擎
  • 做网站建设的电话销售培训计划方案模板
  • java自己做网站免费的关键词优化软件
  • 我做中医培训去哪个网站找学员2023年免费进入b站
  • 做有弹幕视频网站营销策划案
  • 帝国做的网站删除域名后缀百度推广关键词质量度
  • 网站建站报价推广代理平台
  • 中山市城乡住房建设局网站欧洲网站服务器
  • 廊坊网站制作策划百度关键词优化是什么意思