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

若依框架之简历pdf文档预览功能

一、前端

(1)安装插件vue-pdf:npm install vue-pdf

(2)引入方式:import pdf from "vue-pdf";

(3)components注入方式:components:{pdf}

(4)前端预览按钮设置

         <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleShow(scope.row)"
            v-hasPermi="['resumes:resumes:show']"
          >预览</el-button>

 (5)预览弹窗

    <!-- 简历预览框 -->
    <el-dialog :title="title" :visible.sync="show" width="800px"  append-to-body>
      <pdf v-for="pdfPage in previewData.pdfPages" :key="pdfPage" :page="pdfPage" :src="previewData.src"
           width="100%">
      </pdf>
    </el-dialog>

 (6)预览的参数设置

      //简历预览弹窗
      show:false,
      //pdf属性
      previewData:{
        type:"",
        src:"",
        pdfPages:[]
      },

 (7)方法实现,调用showResume方法

将showResume方法返回数据的形式设置成blob流的形式


export function showResume(id){
  return request({
    url: '/resumes/resumes/show/' + id,
    method: 'get',
    responseType: 'blob'
  })
    handleShow(row){
      const id = row.id
      showResume(id).then(res => {
        this.show = true;
        this.title="简历预览"
        let blob = new Blob([res]);
        this.previewData.type="pdf";
        this.previewData.src=URL.createObjectURL(blob);
        let loadingTask=pdf.createLoadingTask(this.previewData.src);
        loadingTask.promise.then(pdf=>{
          this.previewData.pdfPages=pdf.numPages;
        })
      });
    },

二、后端

(1)show方法的实现,入参是前端传回来的简历的id值,根据id值获取简历的存储路径(简历存储在了本地)

    @PreAuthorize("@ss.hasPermi('resumes:resumes:show')")
    @GetMapping("/show/{id}")
    public ResponseEntity<InputStreamResource> show(@PathVariable Long id) throws IOException {
        Resumes resumes=new Resumes();
        resumes=resumesService.selectResumesById(id);
        String path=resumes.getFileUrl();
        FileSystemResource file = new FileSystemResource(path);

        // 设置响应头
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Disposition", String.format("attachment; filename=\"%s\"", file.getFilename()));

        return ResponseEntity
                .ok()
                .headers(headers)
                .contentLength(file.contentLength())
                .contentType(MediaType.parseMediaType("application/octet-stream"))
                .body(new InputStreamResource(file.getInputStream()));
    }

三、实现效果


http://www.kler.cn/a/461323.html

相关文章:

  • BinaryMoS: 提升二值化大语言模型的创新技术
  • 大型ERP系统GL(总账管理)模块需求分析
  • OpenCV-Python实战(14)——轮廓拟合
  • gunicorn开发时候如何自动重启
  • 标准库以及HAL库——按键控制LED灯代码
  • 植物大战僵尸杂交版3.0.2版本
  • 使用Xjar给SpringBoot项目jar包加密
  • Druid连接Oracle数据库,连接失效导致SQL无法执行
  • “云梦乘风起,数智继风华”丨2024韩山师范学院数学与统计学院大数据方向企业微专业结业典礼圆满结束
  • 面试经典150题——滑动窗口
  • Colyseus 的可扩展性
  • 如何确保涡度通量观测数据的准确性?涡度通量光敏感性分析、温度敏感性分析、数据风浪区分析等
  • IP 报头中 IPID 的历史与反思
  • 神经网络-DenseNet
  • list的介绍(详解)
  • STM32 Flash DB的使用方法
  • 小程序基础 —— 02 微信小程序账号注册
  • uniapp顶部导航栏
  • ABS函数:C语言与Excel中的绝对值计算
  • 120.【C语言】数据结构之快速排序(详解Hoare排序算法)