3

I need to generate charts using JFreeChart and then export them to PDF using Apache PDFBOX. I don't want to use iText as it cannot be used in proprietary software.

I searched all over Google, but no luck! Has anyone done it?

Naveen
  • 31
  • 1
  • 2

2 Answers2

5

Copy the OutputStream from your chosen writeChartAs*() method in ChartUtilities to the InputStream used to create a PDXObjectImage in AddImageToPDF. A typical copyStream() implementation is shown here.

Addendum: Alternatively, use piped streams to copy from output to input, as shown here and here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

You can try using JasperReports. They are a bit heavy, but working good.

  • 1
    But JasperReports internally use iText to generate PDF files. Due to some requirements I need to use Apache PDFBOX **ONLY**. – Naveen Aug 12 '11 at 14:26
  • So, than what is the problem actually? You generate an image stream from JFreeChart and then include it into the PDF. Here http://pdfbox.apache.org/userguide/cookbook.html there is a AddImageToPDF sample. – Dmitry Alexandrov Aug 12 '11 at 14:39
  • 1
    The [AddImageToPDF](http://pdfbox.apache.org/apidocs/org/apache/pdfbox/examples/pdmodel/AddImageToPDF.html) creates PDF from a file instead of a stream. And due to some restrictions I cannot save the chart image on server. I need something which will take chart image as stream and then output PDF also as stream. – Naveen Aug 12 '11 at 14:50