Export custom HTML template

后端 未结 1 1275
温柔的废话
温柔的废话 2021-01-21 04:58

Background

Exporting to HTML generates the following:


    
        
        

        
1条回答
  •  失恋的感觉
    2021-01-21 05:54

    The HTML_HEADER parameter of JRHtmlExporterParameter was replaced with:

    HtmlExporterConfiguration.getHtmlHeader()

    For example:

    public byte[] exportHtml(final JasperPrint print) {
        final Exporter exporter = new HtmlExporter();
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
    
        exporter.setConfiguration(createHtmlConfiguration());
        exporter.setExporterOutput(new SimpleHtmlExporterOutput(out));
        exporter.setExporterInput(new SimpleExporterInput(print));
        exporter.exportReport();
    
        return out.toByteArray();
    }
    
    private HtmlExporterConfiguration createHtmlConfiguration()
            throws IOException {
        SimpleHtmlExporterConfiguration shec
                = new SimpleHtmlExporterConfiguration();
    
        shec.setHtmlHeader(getHtmlHeader());
        shec.setHtmlFooter(getHtmlFooter());
    
        return shec;
    }
    
    private String getHtmlHeader() {
        StringBuffer sb = new StringBuffer();
        sb.append("");
        sb.append("");
        sb.append("  ");
        sb.append("  ");
        sb.append("  ");
        sb.append("");
        sb.append("");
        sb.append("");
        sb.append("
    "); return sb.toString(); } private String getHtmlFooter() { // Close the opening tags from getHtmlHeader()... }

    Even better would be to use external resources (such as a database, file, or web page) for the HTML content, rather than hard-coded strings.

    0 讨论(0)
    提交回复
    热议问题