Generate chart with JFreeChart and Apache PDFBOX
Asked Answered
C

2

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?

Clarisclarisa answered 12/8, 2011 at 14:12 Comment(0)
A
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.

Abatis answered 12/8, 2011 at 15:47 Comment(0)
S
0

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

Shyster answered 12/8, 2011 at 14:25 Comment(3)
But JasperReports internally use iText to generate PDF files. Due to some requirements I need to use Apache PDFBOX ONLY.Clarisclarisa
So, than what is the problem actually? You generate an image stream from JFreeChart and then include it into the PDF. Here pdfbox.apache.org/userguide/cookbook.html there is a AddImageToPDF sample.Shyster
The AddImageToPDF 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.Clarisclarisa

© 2022 - 2024 — McMap. All rights reserved.