如何在应用程序文件夹中以 pdf/.xls 格式存储 birt 报告

How to Store birt report in pdf/.xls format in application folder

在 birt 报告中,我可以在屏幕上显示报告以及 .pdf 和 .xls 格式的附件。 为此,我使用了一种方法 runReportAsAttachment() 并将参数和 *.rptdesign 文件位置路径传递给 BirtServletEngine.In 服务方法我得到了字节格式的报告并以 pdf 格式保存了这个字节,我在下面的代码中写了,

try{
            File saveFile = new File("/report/SaveAsFile.pdf");
            if(!saveFile.exists()) {
                saveFile.createNewFile();
            } 
            FileOutputStream fileToDownload = new FileOutputStream(saveFile);

            response.setContentType("application/pdf");
//response got from birtservlet engine 
            ServletOutputStream output = response.getOutputStream();
            //
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] bytes = new byte[10000];
            bos.write(bytes);
            bos.writeTo(output);
            pdfBytes = bos.toByteArray();       
            //
            fileToDownload.write(pdfBytes);
            fileToDownload.flush();
            fileToDownload.close();
        }catch (Exception e) {
            e.printStackTrace();

/report 文件夹下生成空 Pdf。请让我知道如何将 birt 报告存储在文件夹中? 提前致谢。

EngineConfig engineConfig = new EngineConfig();

    engineConfig.setBIRTHome("D:/Reporting/Birt/Birt Softwares/birt-runtime-4_3_2/ReportEngine");
    engineConfig.setLogConfig("C:/temp", Level.FINE);
    Platform.startup(engineConfig);

    IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);

    IReportEngine engine = factory.createReportEngine(engineConfig);

    IReportRunnable openReportDesign = engine.openReportDesign("D:/Birt/Reprt Work/.metadata/br/RemoteSystemsTempFiles/test_report.rptdesign");

    IRunAndRenderTask createRunAndRenderTask = engine.createRunAndRenderTask(openReportDesign);

    PDFRenderOption taskOption = new PDFRenderOption();
    String outPutFile = "D:/out.pdf";
    taskOption.setOutputFormat("pdf");
    taskOption.setOutputFileName(outPutFile);
    createRunAndRenderTask.setRenderOption(taskOption);
    createRunAndRenderTask.run();
    createRunAndRenderTask.close();
    engine.destroy();
    Platform.shutdown();

试试这个。希望它会起作用!!