首页 文章

在java中将Crystal报表导出为PDF

提问于
浏览
4

谁能指导我如何在java中将水晶报表导出为PDF?

我正在使用Crystal Report Server XI .

提前致谢 .

3 回答

  • 0

    我在此处记录了SAP Crystal Reports for Java运行时组件的尖峰测试 - Java Reporting Component(JRC):

    http://www.javathinking.com/2011/09/using-crystal-reports-java-api-to.html

    我使用的是Business Objects 4.0,可能最重要的是获取Java库 - 从以下位置下载“SAP Crystal Reports for Java运行时组件 - Java报告组件(JRC)”:

    http://www.businessobjects.com/campaigns/forms/downloads/crystal/eclipse/datasave.asp

    网上有很多样本可供查看 - 你可能会在这里找到一些帮助:http://wiki.sdn.sap.com/wiki/display/BOBJ/Java+Reporting+Component++SDK+Samples

    一个很好的例子是“JRC EXPORT REPORT”:http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40d580ce-bd66-2b10-95b0-cc4d3f2dcaef

    在我的情况下,我不需要服务器 - 我只使用了JAR文件,RPT文件,数据库和我的CRConfig.xml文件:

    <?xml version="1.0" encoding="utf-8"?>
    <CrystalReportEngine-configuration>
        <reportlocation>..</reportlocation>
        <timeout>0</timeout>
        <ExternalFunctionLibraryClassNames>
            <classname></classname>
        </ExternalFunctionLibraryClassNames>
    </CrystalReportEngine-configuration>
    
  • 1

    这更适用于自动化流程 .

    首先从晶体输出原始字节:

    ReportClientDocument reportClientDoc = new ReportClientDocument();
        reportClientDoc.open(sourceReportFile, OpenReportOptions._openAsReadOnly);
    
        ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) reportClientDoc.getPrintOutputController().export(ReportExportFormat.PDF);
    
        //Release report.
        reportClientDoc.close();
    

    然后创建一个包含导出结果的新文件 .

    File file = new File(exportedFileName);
    
        FileOutputStream fileOutputStream = new FileOutputStream(file);
    
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(byteArrayInputStream.available());
        int x = byteArrayInputStream.read(byteArray, 0, byteArrayInputStream.available());
    
        byteArrayOutputStream.write(byteArray, 0, x);
        byteArrayOutputStream.writeTo(fileOutputStream);
    
        //Close streams.
        byteArrayInputStream.close();
        byteArrayOutputStream.close();
        fileOutputStream.close();
    
  • 3

    您应该拥有Java版的Crystal Reports SDK . 书 Crystal Reports XI Official Guide 提供了必要的细节 .

    您可以使用Java中的任何一个PDF库来执行此操作 . 据我所知,有两个最受欢迎的图书馆,如iTextApache's PDFBox

相关问题