Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to export a canvas to PDF

 
Sarah Raf
Ranch Hand
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sarah Raf
Ranch Hand
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf.
Will surely try it.
 
Sarah Raf
Ranch Hand
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic