javaweb实现pdf预览

  1.  pdf.js下载 http://mozilla.github.io/pdf.js/
  2.  项目中引入pdfjs
  3. 更改pdfjs中文件 view.js 

    代码: var DEFAULT_URL = ''; 默认路径置为空.

  4. 页面代码


    
    Document
    
    




  1. 后台代码
  2. @RequestMapping("/showpdf")
    public void showpdf(HttpServletRequest request,HttpServletResponse response) {
        try {
            String fileId = request.getParameter("fileId");
            System.out.println(fileId);
            File file = new File("E://0621.pdf");
            FileInputStream fileInputStream = new FileInputStream(file);
            response.setHeader("Content-Disposition", "attachment;fileName=0621.pdf");
            response.setContentType("multipart/form-data");
            OutputStream outputStream = response.getOutputStream();
            IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream);
            fileInputStream.close();
            outputStream.flush();
            outputStream.close();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

     

 

 

 

 

 

你可能感兴趣的:(javaweb实现pdf预览)