Export Crystal Reports to pdf in java

Friday, May 27th, 2016 (9 Comments)

In this article, we will do samples export crystal reports to pdf in java. When you know how to call crystal reports in java then next article, we will practice show crystal reports on web application (jsp page).

At first, to use Crystal Reports you must need library of the SAP Crystal Reports. You can search “crjava-runtime” and download the there located archive (around 45mb). Unzip the archive and add the lib directory into your project. This includes all the libraries you have to install to get going with Crystal Reports. The following jars are needed for Export Crystal Reports to pdf in java:

  • com.azalea.ufl.barcode.1.0.jar
  • CrystalCommon2.jar
  • CrystalReportsRuntime.jar
  • cvom.jar
  • DatabaseConnectors.jar
  • commons-collections-3.1.jar
  • commons-configuration-1.2.jar
  • commons-lang-2.1.jar
  • commons-logging.jar
  • icu4j.jar
  • jai_imageio.jar
  • JDBInterface.jar
  • jrcerom.jar
  • keycodeDecoder.jar
  • logging.jar
  • pfjgraphics.jar
  • QueryBuilder.jar
  • webreporting-jsf.jar
  • webreporting.jar
  • XMLConnector.jar
  • xpp3.jar

We have two ways use Crystal Reports is connect database and not connect database.

1. Export Crystal Reports to pdf in java not use connect database (basic)

We have one crystal report simple and one parameter, report will show this parameter and generate to pdf file:

Download demo_1.rpt

Download subreport_1.rpt

If you want to see more detail about Export Crystal Report with Subreport in java

If report has subreport simple (without parameter or parameter get value from main report. In subreport, right click and select Change Subreport links and select ?p_sub_name link to ?p_name) then maybe use code below:

2. Export Crystal Reports to pdf in java use connect database

You have Crystal Reports and this report uses command sql to connect database.

Download oracle_demo_3.rpt

Example: sql command “select * from room where id < {?p_id}”. with p_id is parameter of report and you use Oracle database (need add library ojdbc6.jar), code java below:

Information for use sql server database (need add library sqljdbc4-4.0.jar)

Information for use mysql database (need add library mysql-connector-java-5.1.6.jar):

 

Tags: , , , , ,

Related Posts

core java
Export Crystal Report with Subreport in java
core java
Convert xml to object java and vice versa
core java
Java basic tutorial on lvtutorial.com
core java
Java hibernate manytomany to manage user role

Related Posts

core java
Export Crystal Report with Subreport in java
core java
Convert xml to object java and vice versa
core java
Java basic tutorial on lvtutorial.com
core java
Java hibernate manytomany to manage user role

9 Comments

  1. mohammed sameer

    hi………..

    thank u for posting this. but i want to try this example can u send me a all .jar file.
    and i want to retrive the data from .mdb file and set to CR report.
    please send me the Jar file.
    Thanks

  2. Admin

    Good Tutorial. Thanks.
    Could you please tell me how to handle subreports?

  3. Anil

    Nice tutorial..thanks..
    Could you please share the code for including subreports also in pdf?

      1. Anil

        Thanks Vivan for your Reply..Now it is working fine..
        I have few doubts..if you don’t mind,Kindly explain below scenario?

        Can we export default values from report/subreport without passing parameter/db credentials ?
        ( example:- I have a report/subreport that has a parameter and a query.We are not passing any parameter/db credentials for seeing the preview this report in SAP Crystal Report.but still we can see the preview of that report.The same preview I want to export as PDF.Is this possible?)

        Thanks,
        Vineeth

  4. Vinod

    Your article is so helpful.Can you please guide me how to get connected to DB2 database with the above code.Thanks alot in advance

Leave a Reply

Your email address will not be published. Required fields are marked *