vue-pdf 使用案例

前端代码:

<template>
  <el-dialog
    title="图像浏览"
    :close-on-click-modal="false"
    width="70%"
    top="10px"
    :visible.sync="visible">
    <el-row>
      <el-col :span="24">
        //显示多页
        <div v-if="manyVisible" class="grid-content bg-purple-light"  >
          <pdf v-for="i in numPages" :key="i" :src="pdfSrc" :page="i"></pdf>
        </div>
        //显示单页
        <div  v-if="singleVisible" class="grid-content bg-purple-light">
          <pdf
            :src="pdfSrc"
            :page="pdfPageNum"
          >
          </pdf>
          <div>
            <el-button @click="prePage()">上一页</el-button> <el-button @click="nextPage()">下一页</el-button>
          </div>
        </div>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
  import pdf from "vue-pdf"

  export default {
    data () {
      return {
        visible: false,
        pdfSrc: '',
        pdfPageNum: 1,
        numPages:1,
        manyVisible: false,
        singleVisible: false
      }
    },
    components: {
      pdf,
    },
    methods: {
      init () {
        this.visible = true
        //1.后台获取pdf"
        let src = `/gen/gentable/imageShow/443a5ce9ab98e689ab5ce5bd92e6a1a3e69687e4bbb65c783134342d323032322d3030315c3030312e706466`
        this.$http({
          url: this.$http.adornUrl(src),
          method: 'get',
          params: this.$http.adornParams(),
          responseType: 'arraybuffer'
        }).then(({data}) =>{
            this.manyVisible = true

            let datas =  new Uint8Array(data)
            this.pdfSrc = datas
            //显示多页
            let loadingTask = pdf.createLoadingTask(datas)
            loadingTask.promise.then(pdf => {
              this.numPages = pdf.numPages
            }).catch((err) => {
              console.error('pdf加载失败')
            })

        })

        //2.直接路径
        // this.pdfSrc = "localhost:8080/jg/pdf/test.pdf"
        // this.singleVisible = true
        // let loadingTask = pdf.createLoadingTask(this.pdfSrc)
        // loadingTask.promise.then(pdf => {
        //   this.numPages = pdf.numPages
        // }).catch((err) => {
        //   console.error('pdf加载失败')
        // })

      },
      nextPage() {
        var p = this.pdfPageNum;
        p = p < this.numPages ? p + 1 : 1;
        this.pdfPageNum = p;
      },
      prePage() {
        var p = this.pdfPageNum;
        p = p > 1 ? p - 1 : 1;
        this.pdfPageNum = p;
      },
      // 表单提交
      dataFormSubmit () {

      },

    }
  }
</script>
<style>

</style>

后端代码:

    @GetMapping(value = "/imageShow/{path}")
    public void imageShow(@PathVariable("path") String path,  HttpServletResponse response) throws IOException {
        String rpath = Encodes.decodeHexS(path);
        File file = new File(rpath);
        FileInputStream fis;
        fis = new FileInputStream(file);

        long size = file.length();
        byte[] data = new byte[(int) size];
        fis.read(data, 0, (int) size);
        fis.close();
        if(rpath.endsWith(".pdf")){
            response.setContentType("application/pdf");
        }else{
            response.setContentType("image/png");
        }
        response.setHeader("Content-Disposition", "attachment; filename="+ Encodes.urlEncode(file.getName()));
        OutputStream out = response.getOutputStream();
        out.write(data);
        out.flush();
        out.close();
    }

《察舌辨症新法》

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
vue⼤数据渲染_VueDataV⼤数据可视化模板VueBigScreen vue-big-screen 基于 vue+datav+echart 框架构建的可视化数据⼤屏项⽬,star⾼达1.1K+。提供数据动态渲染、屏幕⾃适应、内部图表 ⾃由替换等功能。 ⽬录结构 安装使⽤ 更换边框 边框是使⽤了 DataV ⾃带的组件,只需要去 views ⽬录下去寻找对应的位置去查找并替换就可以,具体的种类请去 DavaV 官⽹查看。 更换图表 直接进⼊ components/echart 下的⽂件修改成你要的 echarts 模样,可以去echarts 官⽅社区⾥⾯查看案例。 屏幕适配配置 本项⽬借助了 flexible 插件,通过改变 rem 的值来进⾏适配,原设计为 1920px。 ,适配区间为:1366px ~ 2560px,本项⽬有根据 实际情况进⾏源⽂件的更改,⼩屏幕(如:宽为 1366px)。// flexible⽂件位置: `common/flexible.js`,修改部分如下function refreshRem() { var width = docEl.getBoundingClientRect().width; // 最⼩1366px,最⼤适配2560px if (width / dpr < 1366) { width = 1366 * dpr; } else if (width / dpr > 2560) { width = 2560 * dpr; } // 原项⽬是1920px我设置成24等份,这样1rem就是 80px var rem = width / 24; docEl.style.fontSize = rem + 'px'; flexible.rem = win.rem = rem;} 以上就是对这个Vue⼤屏项⽬的简单介绍,如果你想看到更详细的⽂档,那就点击下⾯的链接去看看吧! ok,就分享到这⾥。希望对⼤家有所帮助,喜欢的话可以去看下哈~

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

古智云开

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值