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

一、前端

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

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

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

(4)前端预览按钮设置

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

(5)预览弹窗

java 复制代码
    <!-- 简历预览框 -->
    <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)预览的参数设置

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

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

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

java 复制代码
export function showResume(id){
  return request({
    url: '/resumes/resumes/show/' + id,
    method: 'get',
    responseType: 'blob'
  })
java 复制代码
    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值获取简历的存储路径(简历存储在了本地)

java 复制代码
    @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()));
    }

三、实现效果

相关推荐
霸道流氓气质3 小时前
基于本地 PaddleOCR 的 PDF 文字识别完整技术文档
开发语言·r语言·pdf
桐桐桐4 小时前
PDF 翻译工具横评与自建批量方案:从在线工具到 Python 自动化
python·pdf·自动化
百事牛科技5 小时前
办公文档防护:如何限制 PDF 转换成其他格式文件
windows·pdf
SunnyDays10116 小时前
Java 给 PDF 添加页码:实现“第 X 页,共 Y 页”
java·pdf·页码
2601_965912836 小时前
520MB卷宗合并压缩踩坑实录:PDF文档归档场景的技术选型与性能对比
pdf
霸道流氓气质6 小时前
本地用 Ollama + 视觉模型识别 PDF 技术教程
pdf
经典19928 小时前
解析pdf表格内容
windows·pdf
星花月10 小时前
【无标题】
ai·语言模型·pdf·deep learning
E_ICEBLUE10 小时前
Python 办公自动化:将 PowerPoint (PPT/PPTX) 转换为 PDF 【全面指南】
python·pdf·powerpoint
XLYcmy1 天前
pdf论文处理:CSV输出模式
数据库·python·pycharm·pdf·论文·csv·dify