zoukankan      html  css  js  c++  java
  • controller实现pdf的下载功能

    上代码:

        /**
         * @param lsh
         * @param ywlxdm
         * @return
         * @throws Exception
         */
        @RequestMapping(value = "/viewPdf", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
        public ResponseEntity<byte[]> viewPdf(String lsh, String ywlxdm) throws Exception {
            byte[] content = fpfwCenterService.viewPdf(lsh, ywlxdm);
            ResponseEntity<byte[]> response = null;
            HttpHeaders headers = new HttpHeaders();
            //这行代码比较重要,有这个属性则告知浏览器下载文件,无则使用浏览器打开PDF
            headers.setContentDispositionFormData("name", "filename");
    
            headers.setContentType(MediaType.parseMediaType("application/pdf"));
            headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
            response = new ResponseEntity<byte[]>(content, headers, HttpStatus.OK);
            return response;
        }
     byte[] content = fpfwCenterService.viewPdf(lsh, ywlxdm);
    content为读取到的PDF二进制数组,以上即可实现PDF浏览器端的相关操作。
  • 相关阅读:
    企业云盘安全性如何 怎样部署
    Sentinel 控制台部署
    nginx代理静态页面添加二级目录
    java socket
    IDEA
    golang代码生成器
    es 单节点问题
    代码模板
    错误摘要 HTTP 错误 403.14
    安装.Net Framework 4.6.2无法安装的2种情况
  • 原文地址:https://www.cnblogs.com/somewhater/p/7366193.html
Copyright © 2011-2022 走看看