wood burning stoves 2.0*
The moose likes Java in General and the fly likes How to export a canvas to PDF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to export a canvas to PDF" Watch "How to export a canvas to PDF" New topic
Author

How to export a canvas to PDF

Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Hi,
Does Java have an API to export a canvas to PDF format? or any other 3rd party APIs can be used?

Regards,
Sarah
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

There are a number of libraries for working with PDF files in Java.

What do you mean by "canvas"; do you mean an HTML 5 canvas? If yes, then you're talking about JavaScript, which is something that does not have very much to do with Java.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
If Canvas refers to the AWT object, then it's probably easier to export its contents to an image, and then add the image to a PDF using a library such as iText.


Ping & DNS - my free Android networking tools app
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Jesper de Jong wrote:There are a number of libraries for working with PDF files in Java.

What do you mean by "canvas"; do you mean an HTML 5 canvas? If yes, then you're talking about JavaScript, which is something that does not have very much to do with Java.


Thanks Jesper.
I am using Open GL libraries and from my Java code, I am referring to the Canvas, using the getCanvas() method. So basically my question is all about Java. And yes I did check out the iText library. Thou i'm still trying to use it..

Regards,
Sarah
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Ulf Dittmer wrote:If Canvas refers to the AWT object, then it's probably easier to export its contents to an image, and then add the image to a PDF using a library such as iText.


Yes Ulf, its an AWT object, but it does have openGL libraries too. How could i export the contents to an image?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
See http://stackoverflow.com/questions/408042/vector-graphics-in-itext-pdf for how to add a Graphics2D to a PDF using iText.
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Thanks Ulf.
Will surely try it.
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Ok here's the problem I am facing... my image is I need to export only the chart part of my image into PDF format.
I tried to this :


But my chart is dynamic. It refreshes every time I perform some mouse action.. So I don't want to explicitly specify my chart image. How do I go about it???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
At any given point in time the chart is static :-) You should be able to draw it onto a given Graphics2D object, no?
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Thanks Ulf...
I found the API to capture the image instance and now I got it in the PDF format... Thanks so much for the suggestions

Regards,
Sarah
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to export a canvas to PDF