简体   繁体   English

在java中将Crystal报表导出为PDF

[英]Export Crystal reports to PDF in java

Can anyone guide me on how to export crystal reports into PDF in java? 谁能指导我如何在java中将水晶报表导出为PDF?

I am using Crystal Report Server XI. 我正在使用Crystal Report Server XI。

Thanks in advance. 提前致谢。

I've documented my spike test for the SAP Crystal Reports for Java runtime components – Java Reporting Component (JRC) here: 我在此处记录了SAP Crystal Reports for Java运行时组件的尖峰测试 - Java Reporting Component(JRC):

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

I was using Business Objects 4.0, and probably the most important thing was to get the Java library – download 'SAP Crystal Reports for Java runtime components – Java Reporting Component (JRC)' from: 我使用的是Business Objects 4.0,可能最重要的是获取Java库 - 从以下位置下载“SAP Crystal Reports for Java运行时组件 - Java报告组件(JRC)”:

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

There are a lot of samples on the web to look at – you might find something to help here: http://wiki.sdn.sap.com/wiki/display/BOBJ/Java+Reporting+Component++SDK+Samples 网上有很多样本可供查看 - 你可能会在这里找到一些帮助: http//wiki.sdn.sap.com/wiki/display/BOBJ/Java+Reporting+Component++SDK+Samples

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

In my case I didn't need a server - I just used the JAR files, the RPT file, the database and my CRConfig.xml file: 在我的情况下,我不需要服务器 - 我只使用了JAR文件,RPT文件,数据库和我的CRConfig.xml文件:

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

This is more for an automated process. 这更适用于自动化流程。

First get the raw byte export from the crystal: 首先从晶体输出原始字节:

 ReportClientDocument reportClientDoc = new ReportClientDocument();
    reportClientDoc.open(sourceReportFile, OpenReportOptions._openAsReadOnly);

    ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) reportClientDoc.getPrintOutputController().export(ReportExportFormat.PDF);

    //Release report.
    reportClientDoc.close();

Then Create a new file that will contain the exported result. 然后创建一个包含导出结果的新文件。

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

You should have Java edition of Crystal Reports SDK. 您应该拥有Java版的Crystal Reports SDK。 The Book Crystal Reports XI Official Guide provides necessary details. Book Crystal Reports XI官方指南提供了必要的细节。

You can use any one of the PDF Library in Java to do that. 您可以使用Java中的任何一个PDF库来执行此操作。 As far as I know, there are two most popular libraries like iText and Apache's PDFBox 据我所知,有两个最受欢迎的库,如iTextApache的PDFBox

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM