引用pdf插件在线预览的问题

来源:互联网 发布:编程之魂 pdf 编辑:程序博客网 时间:2024/06/16 12:38

引用pdf插件在线预览带中文名称文件报错解决

预览中文错误


解决

  • 由图可知插件pdf.js在解析带有中文的pdf文件时出现乱码问题
    直接去改pdf.js比较麻烦且不好改,我们可以在预览pdf时候这么定义:
    PrintWriter out = response.getWriter();
    JSONObject jsonObj = new JSONObject();
    byte[] bs=fileByte;
    String fileName = "view.pdf";
    String fullFileName = getServletContext().getRealPath("/zyzb/download/" + fileName);
    File file = new File(fullFileName);
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(bs);

    String fileUrl = request.getContextPath() + “/zyzb/download/” + fileName;
    String url = request.getContextPath() + “/” +
    “zyzb/pdfjs/web/viewer.html?file=” + fileUrl;
    jsonObj.put(“url”, url);
    out.println(jsono);
    xx.js:
    window.open(url);
    *自己随意取一个英文名字这样就不用考虑中文pdf文件的问题
原创粉丝点击