Creating a PDF from a Draw2D Canvas
I'm looking for a way to build a PDF from a Draw2D canvas. I believe I've seen a way to do this from Java2D, but not Draw2D. There are many graphical elements involved (as well as text) so I don't think I can go the XSLT route. Does anyone have any suggestions开发者_如何学Python?
Maybe you can succeed using "jPod".
It comes with a simple example how to create PDF content using its "CSCreator", which publishes the PDF graphics operation primitives as an API. While i do not use draw2d, i assume it shouldn't be to hard to map to this API.
Roughly it should go like this
- open/create PDF
- select/create page
- create a CSCreator on this page
- call drawing primitives
- close and save...
iText is a library for creating PDF from java application. iText implements its adapter for Graphics2D class, see this. So you can draw any AWT/Swing component to the PDF.
Eclipse Graphiti contains another adapter. It adapts draw2d Graphics to awt's Graphics2D. You can download it and maybe little edit for your needs. So using those adapters you can draw your root figure to the PDF. It works, I have tried that.
精彩评论