1

I created a jasper report and now I need to export that report to pdf format. This is my code for that.

        // compiles jrxml
        JasperCompileManager.compileReportToFile(reportName + ".jrxml");
        // fills compiled report with parameters and a connection
        JasperPrint print = JasperFillManager.fillReport(reportName + ".jasper", parameters, connection);

        // to view the report
        //JasperViewer.viewReport(print, false);

        // export repor to pdf
        JasperExportManager.exportReportToPdfFile(print, "fromXml.pdf");

When I view the report using JasperViewer, it works fine. But When I exporting the report into pdf format, it gives me the following exception.

Exception in thread "main" java.lang.NoClassDefFoundError: com/itextpdf/text/DocumentException

But I have put the iText jar into my libraries.

enter image description here

But one thing, I had another version of iText jar before. It gave me the same exception. I thought that there may be some issues with the version of it.(I followed a tutorial, so I added the same jar as they had used in the tutorial replacing the new jar I had used).

but still the problem remains. I thought this may be the issue now(the accepted answer of the question). But I do not know how to fix it. I removed the entire library and added it again with iText jar which had been used by the tutorial. But I had no luck.

Could you please help me to overcome this issue. Thank you!

Community
  • 1
  • 1
vigamage
  • 1,975
  • 7
  • 48
  • 74

1 Answers1

7

You need to upgrade your iText-2.1.7.jar file to latest version as earlier the package that was used by jar is com.lowagie...

See the change list here which says it has changed the package name.

SMA
  • 36,381
  • 8
  • 49
  • 73
  • now I get `java.lang.NoClassDefFoundError: com/itextpdf/text/pdf/PdfAWriter` exception – vigamage Feb 08 '15 at 14:30
  • Yes because you dont have that class in any of the jar that you have showed in the classpath screen shot. – SMA Feb 08 '15 at 14:37
  • but it should come under `itextpdf.jar`. isn't it? – vigamage Feb 08 '15 at 14:40
  • Yes you are right. But you are using old version of the jar file. You should upgrade it as the package that you are looking for is in latest version i.e. 5.X. You wont find com.itextpdf.text.pdf.PdfAWriter.class in your itextpdf-2.1.7.jar – SMA Feb 08 '15 at 14:42
  • thanks. found it here.http://stackoverflow.com/questions/15118163/itextpdf-library-cant-find-the-class-com-itextpdf-text-pdf-pdfawriter – vigamage Feb 08 '15 at 14:44