Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Java2D / PDF Backend

Started by Frederick Aug 25, 2008 at 5:04 AM 3 replies 1.4k views
Original Post
Frederick
Frederick
Hi there, I am looking for a while for a pdf backend for java2d. I´d like to have this to enable some WYSIWYG document editing. I want something that translates my java2d instructions into PDF =) The only thing I could find so far is batik - it does the job for svg but not pdf. Well at least thats a start. I begin to think about dropping java2d and use cairo for rendering. I am not sure if cairo is a good trade for java2d, but it looks really nice and provides ps and pdf backends, I also would have to write some bindings *sigh* Looking forward to suggestions!
CaptainJester
CaptainJester
iText is a pretty good PDF creator for Java. http://www.lowagie.com/iText/

Since PDF supports images you can just draw to a BufferedImage and transfer the data to iText with this code:
ImgRaw pdfImage = new ImgRaw(IMAGE_WIDTH, IMAGE_HEIGHT, 3, 8,     ((byte[])image.getRaster().getDataElements(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null)));

ImgRaw is a class from iText and image is a BufferedImage
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Frederick
Frederick
Thanks for the snippet Captain Jester (=

Okay, thats actually an option, but I really would like to have vectors in the pdf.

Oh there *SHOULD* be a way to do that.

Otherwise I would have to stick with svg or cairo (not so sure about this one =))

Maybe any other ideas !?

Thanks!
CaptainJester
CaptainJester
This link is a tutorial page on how to draw directly to a page with the Graphics2D object.

http://itextdocs.lowagie.com/tutorial/directcontent/graphics2D/index.php
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Frederick
Frederick
Wow! Thanks a lot!

I did look into iText but seemingly not close enough !
Thats exactly what I need ! Cool !

Thank you very much, I would have never found that on my own...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.