[英]Export Crystal reports to PDF in java
谁能指导我如何在java中将水晶报表导出为PDF?
我正在使用Crystal Report Server XI。
提前致谢。
我在此处记录了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>
这更适用于自动化流程。
首先从晶体输出原始字节:
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();
您应该拥有Java版的Crystal Reports SDK。 Book Crystal Reports XI官方指南提供了必要的细节。
您可以使用Java中的任何一个PDF库来执行此操作。 据我所知,有两个最受欢迎的库,如iText和Apache的PDFBox
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.