1.首先下载 pdf.js

2.将pdf解压,放入项目中webapp下

移动端网页打开查看 pdf 文件

3.后台处理:根据url获取pdf,把数据写入到输出流

    js:

download: function (url) {
    var urls = '${contextPath}/***/open?urls='+url;
    window.location.href = "${ctxStatic}/pdf/web/viewer.html?file="+encodeURIComponent(urls);
},

    后台:

@RequestMapping(value = "/open",method = RequestMethod.GET)
public void open(String urls,HttpServletResponse response) throws IOException {
    URL httpUrl=new URL(urls);
    HttpURLConnection httpURLConnection=(HttpURLConnection) httpUrl.openConnection();
    InputStream inputStream=httpURLConnection.getInputStream();
    response.setHeader("Content-disposition", "attachment; filename=" + new String( "PDF文件名".getBytes("gb2312"), "ISO8859-1" ) );
    response.setContentType("multipart/form-data");
    OutputStream outputStream = response.getOutputStream();
    IOUtils.write(IOUtils.toByteArray(inputStream),outputStream);
}
4.调用事件,就会打开pdf了

相关文章:

  • 2021-11-14
  • 2021-05-20
  • 2022-01-05
  • 2021-12-31
  • 2021-11-06
  • 2021-12-06
  • 2021-10-18
猜你喜欢
  • 2021-11-23
  • 2022-01-20
  • 2021-12-06
  • 2021-09-21
  • 2022-01-22
  • 2021-05-16
  • 2021-10-18
相关资源
相似解决方案