0

What is the best way to draw an SVG images to EPS files in Java? Like I understood I could parse the SVG file by myself and then draw every shape/line/whatever with VectorGraphics2D via the graphics interface to an EPS File. The problem is that then I have to find a corresponding method for every SVG Command in Java graphics.

Is there any Library that can convert SVG files to EPS, or what can draw the individual SVG commands to an graphics context?

KenS
  • 30,202
  • 3
  • 34
  • 51
XleKle
  • 73
  • 6
  • Off the top my head - you "might" be able to covert an SVG to EPS through [ImageMagick](https://stackoverflow.com/questions/13697406/how-to-convert-svg-to-eps-using-imagemagick) - it provides command line support – MadProgrammer Jul 26 '18 at 08:48
  • I already thought about something like this. But I hoped that there would be an Java approach for this. I have to convert **a lot** (a few thousand per minute) of files, and I would like to avoid writing them to the filesystem. Furthermore native calls are so *error-prone* and I have no experience in handling this kind of stuff. – XleKle Jul 26 '18 at 09:10
  • I didn’t find a better solution when I was doing similar things, but that was a while ago – MadProgrammer Jul 26 '18 at 09:29
  • So you used Imagemagick or Inkscape? Because like the one in your linked question pointed out Imagemagick will raster the images. – XleKle Jul 26 '18 at 09:34
  • I think I was using ImageMagic to convert from ESP to SVG from memory, but you might consider using Inkscape as well and see what you get – MadProgrammer Jul 26 '18 at 10:01
  • And what performance do you got? I just tried Inkscape, and it took 0.5s. But It also printed a lot of garbage, so I am not sure if this added a delay to it. 600 files per minute is the absolute absolute minimum that I need to archive. Like I understood this operation was single threaded, so I might get 4/8 times this speed in parallel. – XleKle Jul 26 '18 at 10:12
  • You might consider a thread pool ;/ – MadProgrammer Jul 26 '18 at 10:34
  • Yes. On this part I know what to do. Just curious because I hopped for a more java like in memory approach. – XleKle Jul 26 '18 at 10:39
  • I'm not personally aware of any Java libraries which support EPS and most of the SVG libraries are generally limited, I've found Apache Bakkit reasonable, but it's quite large – MadProgrammer Jul 26 '18 at 10:57
  • VectorGraphics2D is handling EPS Files just fine, but I still have to figure out how to write SVG into an AWT graphics context. Certainly I could parse the SVG and just call the corresponding graphics method. This will result in a lot of _if_ statements. – XleKle Jul 26 '18 at 11:53
  • Supposedly you can convert SVG to EPS using a combination of [Apache Batik](https://xmlgraphics.apache.org/batik/) and [Apache FOP](https://xmlgraphics.apache.org/fop/). However I haven't tried it myself. – Paul LeBeau Jul 27 '18 at 20:07

0 Answers0