PDF预览插件

下载PDF静态资源包:

pdf文件格式预览包

将下载资源文件解压放在Vue项目public目录下:

在这里插入图片描述

Vue页面引用方式:

pdfFileUrl为Vue定义的PDF地址变量

<!--
 * @Description: PDF文件格式预览组件
 * @version: 
 * @Author: zhao wen bo
 * @Date: 2022-03-07 15:21:08
 * @LastEditors: Please set LastEditors
 * @LastEditorTime: Do not edit
 * @FilePath: \middleground-vue\src\views\skyvis\wszz\sign\pdfPreview.vue
-->
<template>
  <div class="watch-pdf-file">
    <iframe
      ref="pdfIframe"
      :src="'/static/pdf/web/viewer.html?file=' + encodeURIComponent(pdfFileUrl)"
      frameborder="0"
      style="width: 100%; height: 100%"
    ></iframe>
  </div>
</template>

<script>
import { getAction } from '@/api/manage'
export default {
  name: 'PdfPreview',
  components: {},
  data() {
    return {
      // 查询PDF路径id
      pdfId: '1234567',
      // 后台生成pdf地址
      pdfFileUrl: '',
      url: {
        // 获取签字文书列表
        queryPdfUrl: '/middleground/pdfFileById',
      },
    }
  },
  methods: {
    // 查询pdf地址接口
    queryPdfFileUrl() {
      let that = this
      let params = {
        id: that.pdfId,
      }
      getAction(that.url.queryPdfUrl, params).then((res) => {
        if (res.success) {
          let result = res.result
          that.pdfFileUrl = result.PdfUrl
        } else {
          that.$message.warning('未查找到PDF地址!')
        }
      })
    },
  },
  created() {
    let that = this
    that.queryPdfFileUrl()
  },
}
</script>

<style scoped>
.watch-pdf-file {
  width: 500px;
  height: 700px;
}
</style>

Tips:具体接口和变量名定义可根据自己需求修改

按上面操作即可查看PDF文件支持页面预览

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值