若依框架之简历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()));
    }

三、实现效果

相关推荐
软件工程小施同学20 分钟前
计算机学报 2025年 区块链论文 录用汇总 附pdf下载
pdf·区块链
VB5944 小时前
《中国传世名画》《中国传世山水画》《中国传世人物画》百科全书式的中国名画,PDF,294M
pdf
家庭云计算专家4 小时前
ONLYOFFICE深度解锁系列.13-如何复制、重新排序 PDF 页面:onlyoffice 9.0.3 新功能
pdf·onlyoffice·协作空间·onlyoffice开发版·onlyoffice新功能·onlyoffice开发者版
Eiceblue2 天前
PDF转Markdown - Python 实现方案与代码
开发语言·vscode·python·pdf
Bruce_Liuxiaowei2 天前
Python实现PDF按页分割:灵活拆分文档的技术指南
windows·python·pdf
烛九幽-子麟2 天前
精通Python PDF裁剪:从入门到专业的三重境界
开发语言·python·pdf
じòぴé南冸じょうげん3 天前
Vue中最简单的PDF引入方法及优缺点分析
前端·javascript·vue.js·pdf
开心就好13145203 天前
前端项目下载发票pdf文件要求改文件名笔记
前端·笔记·pdf
诸葛大钢铁3 天前
PDF转Word的简单方法
pdf·word
菜鸟看点3 天前
QGraphicsScene导出为PDF
c++·pdf