itext,Flying Saucer:xhtml to pdf ClassCastException

时间:2015-05-13 11:38:32

标签: java itext flying-saucer

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();
}

这是例外..

  

java.lang.ClassCastException:org.xhtmlrenderer.render.BlockBox无法强制转换为org.xhtmlrenderer.newtable.TableBox

1 个答案:

答案 0 :(得分:0)

commit已解决此问题。您可以download the Class并将其放置在src目录中,这样就不必重建jar。