0

I have written a Java code, which shows a line chart on a JPanel on clicking a button. What I want is to show that line chart in my PDF file, using the Java PDF library, itextpdf. The problem is that there is no image of pie chart created in a folder. I can easily paste an existing image, e.g. a pie chart, in a PDF file. So in this scenario (when I don't have any image file of a pie chart), give me an idea how to show this chart in a PDF.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Xara
  • 8,748
  • 16
  • 52
  • 82
  • 3
    Not knowing which PDF library you're using it's hard to answer exactly, but you can [make a JPanel render its contents into an image](http://stackoverflow.com/questions/1349220/convert-jpanel-to-image). Then you might be able to use the resulting BufferedImage directly in your PDF library, or you can write its contents into a temporary file using [`ImageIO.write()`](http://docs.oracle.com/javase/6/docs/api/javax/imageio/ImageIO.html). – millimoose Apr 12 '12 at 17:52

2 Answers2

1

May be one of these could help

http://www.javaworld.com/javaworld/jw-12-2006/jw-1209-swing.html

or

How do I paint Swing Components to a PDF file with iText?

Community
  • 1
  • 1
StanislavL
  • 56,971
  • 9
  • 68
  • 98
-2

There are lots of commercial and Open Source PDF viewers for Java. What is wrong with them?

mark stephens
  • 3,205
  • 16
  • 19