本文介绍了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();
}

这是个例外.

推荐答案

提交已解决此问题.您可以下载Class 并将其放置在src目录中,这样就不必重建jar.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 10:57