添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
import download from 'downloadjs'

③在下载的方法里调用download就可以实现下载了

*如果下载后的PDF文件为空或者提示不支持打开该类型文件或文件已损坏。请检查请求时是否写入以下代码:reponseType:'blob'

二、PDF文件直接页面打开的方法

首先 说下这方面的需求: 向后台发送对应的id参数 拿到相关 pdf 文件 如下: 由于没做过 pdf 预览功能 在网上看了好多教程 眼花缭乱 同时也试了很多种 不是报错 就是 报错 其中Vue的教程 下载 插件vue- pdf 根据文档教程满足我的需求 也 实现 了我想要的效果 但是做的项目是之前的老项目 纯原生写的 所以还是要看 pdf .js的官网 废话不多说 直接说下我过程中 实现 的步骤: ①: 到官网 下载 包https://github.com/mozilla/ pdf .js/releases
首先是自己整理的帮助类 import cn.bt.common.utils.StringUtils; import cn.bt.modules.process.instance.enums.InstanceStatusEnum; import com.itext pdf .text.*; import com.itext pdf .text. pdf .*; import 1、设置字体 static BaseFont FontBase = BaseFont.CreateFont("C:\\WINDOWS\\FONTS\\STSONG.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); static iTextSharp.text.Font bodyFont = new iTextSharp.text.Font(FontBase, 12); static iTextSharp.text.Font titleFont = new ```java @GetMapping("/get Pdf ") public ResponseEntity<byte[]> get Pdf () throws IOException { // 从 文件 系统或网络中获取 pdf 文件 的 InputStream 对象 InputStream in = new FileInputStream(new File("example. pdf ")); // 设置响应头信息 HttpHeaders headers = new HttpHeaders(); headers.add("Content-Disposition", "attachment;filename=example. pdf "); // 设置 下载 文件 名称 // 将 InputStream 转换为 byte 数组 byte[] bytes = IOUtils.toByteArray(in); // 返回 ResponseEntity 对象 return ResponseEntity.ok() .headers(headers) .contentType(MediaType.APPLICATION_ PDF ) .contentLength(bytes.length) .body(bytes); 这样,微信小程序就可以通过请求该 接口 下载 并展示 pdf 文件 了。