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

时间:2015-04-08 10:00:38

标签: weblogic birt eclipse-kepler

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

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文件夹下生成Empty Pdf。请让我知道如何在文件夹中存储birt报告? 在此先感谢。

1 个答案:

答案 0 :(得分:1)

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();

试试这个。它会有希望地工作!!