itext,飞碟:xhtml到pdf ClassCastException [英] itext, Flying Saucer: xhtml to pdf ClassCastException

查看:94
本文介绍了itext,飞碟:xhtml到pdf ClassCastException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

提交已解决此问题.您可以

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.

这篇关于itext,飞碟:xhtml到pdf ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆