itext, Flying Saucer: xhtml to pdf ClassCastException

巧了我就是萌 提交于 2019-12-24 09:07:49

问题


public void createPDF() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    HttpSession session = (HttpSession) externalContext.getSession(true);
    String url = "http://localhost:8080/comap/pages/admin/student.xhtml";
    try {
        ITextRenderer renderer = new ITextRenderer();
        renderer.setDocument(url);
        renderer.layout();
        HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
        response.reset();
        response.setContentType("application/pdf");
        response.setHeader("Content-Disposition","C://user//first.pdf");
        java.io.OutputStream browserStream = response.getOutputStream();
        renderer.createPDF(browserStream);
        browserStream.close();
        session.invalidate();
    } catch (Exception ex) {
    ex.printStackTrace();
    }

    facesContext.responseComplete();
}

here is the exception..

java.lang.ClassCastException: org.xhtmlrenderer.render.BlockBox cannot be cast to org.xhtmlrenderer.newtable.TableBox


回答1:


This commit has fixed the issue. You can download the Class and place it in your src directory so that you don't have to rebuild the jar.



来源:https://stackoverflow.com/questions/30213697/itext-flying-saucer-xhtml-to-pdf-classcastexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!