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

三、实现效果

相关推荐
庖丁AI16 小时前
PDF 转 Markdown 工具怎么选?AI 知识库和 RAG 场景要注意什么
人工智能·pdf·文档解析
几层山下17 小时前
WPS的word文档转pdf java实现不乱格式生成-已解决
java·pdf·word·wps
DevOpenClub2 天前
PDF 多格式解析如何避免混用输出:TEXT、HTML、XML 与 TAG 数据契约
xml·前端·数据库·pdf·html
DevOpenClub2 天前
网页证据如何长期复核:快照、静态 HTML 与 PDF 归档链路
前端·pdf·html
拆房老料2 天前
LibreOffice 26.8 发布后,再看 BaseMetas FileView 的 Office 转 PDF 技术路线
pdf·word·开源软件·ppt·格式工厂
开开心心就好2 天前
手机悬屏翻译工具外语游戏漫画APP全覆盖
android·前端·javascript·python·游戏·pdf·html
redfred2 天前
Koodo Reader 使用教程:开源电子书阅读器 epub/pdf/mobi/azw3 全格式 多端同步 AI翻译 笔记高亮
人工智能·pdf·开源
Metaphor6922 天前
如何在 Python 环境中裁剪 PDF 页面
python·pdf
开开心心就好2 天前
手机精确倒计时工具悬浮窗口秒数实时显示
android·前端·javascript·jupyter·智能手机·pdf·html
jayson.h3 天前
python——pdf编辑
前端·python·pdf