我看不到DynamicReport生成的pdf

时间:2022-04-18 21:07:54

i'm making a pdf report, i'm using Jsf, primefaces, actually i can see the report in a dialog without problems but when i download the pdf, it's can't show. The message from adobe reader is that file is damaged.

我正在制作一个pdf报告,我正在使用Jsf,primefaces,实际上我可以在对话框中看到报告没有问题但是当我下载pdf时,它无法显示。来自adobe reader的消息是该文件已损坏。

This is my code:

这是我的代码:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        DynamicReports.report()
                .setTemplate(Plantillas.reportTemplate)
                .columns(stateColumn, statePorc)
                .title(Templates.createTitleComponent2("Tittle"))
                .summary(
                        DynamicReports.cht.barChart()
                        .setTitleFont(boldFont)
                        .setCategory(stateColumn)
                        .series(
                                DynamicReports.cht.serie(itemColumn).setSeries(stateColumn)
                        )
                        .setCategoryAxisFormat(DynamicReports.cht.axisFormat().setLabel("Label"))
                )
                .pageFooter(Templates.footerComponent)
                .setDataSource(createDataSource3())
                .toPdf(baos);
        InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
        barStream = new DefaultStreamedContent(inputStream, "application/pdf", "example.pdf");
        setBarStream(barStream);
    } catch (DRException e) {
        e.printStackTrace();
    }

1 个解决方案

#1


set this way to export.

设置这种方式导出。

report.toPdf(new FileOutputStream(new File("D:/report11.pdf")));

report.toPdf(new FileOutputStream(new File(“D:/report11.pdf”)));

#1


set this way to export.

设置这种方式导出。

report.toPdf(new FileOutputStream(new File("D:/report11.pdf")));

report.toPdf(new FileOutputStream(new File(“D:/report11.pdf”)));