美文网首页
pdf文件浏览器在线预览

pdf文件浏览器在线预览

作者: 让你变好的过程从来都不会很舒服 | 来源:发表于2023-04-25 16:44 被阅读0次
@RequestMapping(value = "/showpdf.do")
    public void showpdf(HttpServletRequest request, HttpServletResponse response, Model model) {
        try {
            File file = new File("E:/123.pdf");

            FileInputStream fileInputStream = new FileInputStream(file);

            response.setHeader("Content-Type", "application/pdf");

            OutputStream outputStream = response.getOutputStream();

            IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream);

        } catch(Exception e) {

            e.printStackTrace();

        }

    }
    
    /**
     * pdf文件浏览器在线预览
     *
     * @param attaOid
     * @return
     * @author jiaq
     * @date 2023年04月26日
     */
    @RequestMapping("/showpdf.do")
    public void showPdf(HttpServletResponse response,String attaOid){
        File file = new File("E:/123.pdf");
        if (file.exists()){
            byte[] data = null;
            try {
                FileInputStream input = new FileInputStream(file);
                data = new byte[input.available()];
                input.read(data);
                response.getOutputStream().write(data);
                input.close();
            } catch (Exception e) {
                System.out.println(e);
            }
        }else{
            return;
        }
    }

相关文章

网友评论

      本文标题:pdf文件浏览器在线预览

      本文链接:https://www.haomeiwen.com/subject/ojkmjdtx.html