在 Java 中将 Crystal 报表导出为 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3178778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Export Crystal reports to PDF in java
提问by ikvenu2000
Can anyone guide me on how to export crystal reports into PDF in java?
谁能指导我如何在java中将水晶报告导出为PDF?
I am using Crystal Report Server XI.
我正在使用水晶报表服务器 XI。
Thanks in advance.
提前致谢。
回答by Venkat
You should have Java edition of Crystal Reports SDK. The Book Crystal Reports XI Official Guideprovides necessary details.
你应该有 Java 版的 Crystal Reports SDK。本书Crystal Reports XI 官方指南提供了必要的详细信息。
You can use any one of the PDF Library in Java to do that. As far as I know, there are two most popular libraries like iTextand Apache's PDFBox
您可以使用 Java 中的任何一种 PDF 库来执行此操作。据我所知,有两个最流行的库,如iText和Apache 的 PDFBox
回答by Glstunna
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();
回答by prule
I've documented my spike test for the SAP Crystal Reports for Java runtime components – Java Reporting Component (JRC) here:
我在此处记录了针对 Java 运行时组件的 SAP Crystal Reports – Java 报告组件 (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 runtime components - Java Reporting Component (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 出口报告”: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>