Hello,
I want to write a Java program that will load Inkscape SVG and parse it. Specifically, I want to be able extract a particular path out of the SVG by its id attribute and do some additional processing with it. This processing may include finding its length, plotting a point a distance along it, and displaying it on the screen. The Batik library is one possible answer, but I am having a difficult time learning it. Is there a simpler library? In either case, could some sample code be provided?
Thanks,
Craig
Parsing SVG with an external program in Java
-
- Posts: 13
- Joined: Thu Nov 15, 2012 12:14 pm
Re: Parsing SVG with an external program in Java
Hello
Just to point to SNAP, for example:
http://www.fabacademy.org/archives/2014 ... ngSnapSVG/
As far as I know, there was a specific subset of javacript or (ecmascript?), for dealing with SVG. There were specific functions to get the length, or the bounding box, or the style of SVG objects. It wasn't neccesary to include external libraries.
Now... how to find it in google ??
Greetings
Just to point to SNAP, for example:
http://www.fabacademy.org/archives/2014 ... ngSnapSVG/
As far as I know, there was a specific subset of javacript or (ecmascript?), for dealing with SVG. There were specific functions to get the length, or the bounding box, or the style of SVG objects. It wasn't neccesary to include external libraries.
Now... how to find it in google ??
Greetings
If you have problems:
1.- Post a sample (or samples) of your file please.
2.- Please check here:
http://tavmjong.free.fr/INKSCAPE/MANUAL/html/index.html
3.- If you manage to solve your problem, please post here your solution.
1.- Post a sample (or samples) of your file please.
2.- Please check here:
http://tavmjong.free.fr/INKSCAPE/MANUAL/html/index.html
3.- If you manage to solve your problem, please post here your solution.
Re: Parsing SVG with an external program in Java
I don't know enough about JS libraries to be able to compare them. I actually just recently learned what a JS library is. I've heard about Snap.svg, and D3.js Afaiu, D3.js is quite powerful, but not very focussed on SVG; while Snap.svg is smaller, but is more focussed on SVG. Note that's my very, very newbie impression (newbie to JS, not to Inkscape), and I might not have explained what I mean in a technically correct way.
I'm in the process (STILL!) of writing a page for the Inkscape website about animation and Inkscape. Although animation may not be exactly what you're after (I'm not sure what "parsing" is), you still may find some help with some links at the bottom of this draft of the page. Unfortunately, it's exactly the section you need, that hasn't been written yet. But you might still find some help with the links there. Note that some of them are not really links, just URLs. But afaik, they are correct.
Actually, I'm not sure if you can see the page. Let's try it. Please note this is a draft, and may change significantly before it's ready to go live on the website. Can you see this: https://inkscape.org/en/animation/ ? If you can't see it, I'll copy some links over here for you
I'm in the process (STILL!) of writing a page for the Inkscape website about animation and Inkscape. Although animation may not be exactly what you're after (I'm not sure what "parsing" is), you still may find some help with some links at the bottom of this draft of the page. Unfortunately, it's exactly the section you need, that hasn't been written yet. But you might still find some help with the links there. Note that some of them are not really links, just URLs. But afaik, they are correct.
Actually, I'm not sure if you can see the page. Let's try it. Please note this is a draft, and may change significantly before it's ready to go live on the website. Can you see this: https://inkscape.org/en/animation/ ? If you can't see it, I'll copy some links over here for you
Basics - Help menu > Tutorials
Manual - Inkscape: Guide to a Vector Drawing Program
Inkscape Community - Inkscape FAQ - Gallery
Inkscape for Cutting Design
Manual - Inkscape: Guide to a Vector Drawing Program
Inkscape Community - Inkscape FAQ - Gallery
Inkscape for Cutting Design
Re: Parsing SVG with an external program in Java
Just a hint (@hulf2012, @brynn): Java ≠ JavaScript.
Re: Parsing SVG with an external program in Java
Right ~suv! I know that, and I noticed that in the message, and I thought about it. But in all the 8 years I've been learning Inkscape, I've never heard of anyone using Java with Inkscape or with SVG. And I've never seen a message in this forum about using Java with Inkscape or SVG. So I thought it might have been the op not stating the question clearly.
Of course I could have given a wrong answer. It's happened before, and I'm quite sure it will happen again. I will always apologize when that happens. But isn't that how we learn? Well, at least it's 1 way to learn
Of course I could have given a wrong answer. It's happened before, and I'm quite sure it will happen again. I will always apologize when that happens. But isn't that how we learn? Well, at least it's 1 way to learn
Basics - Help menu > Tutorials
Manual - Inkscape: Guide to a Vector Drawing Program
Inkscape Community - Inkscape FAQ - Gallery
Inkscape for Cutting Design
Manual - Inkscape: Guide to a Vector Drawing Program
Inkscape Community - Inkscape FAQ - Gallery
Inkscape for Cutting Design
Re: Parsing SVG with an external program in Java
Homer Simpson mode:
Ough!
Totally wrong here
Ough!
Totally wrong here
If you have problems:
1.- Post a sample (or samples) of your file please.
2.- Please check here:
http://tavmjong.free.fr/INKSCAPE/MANUAL/html/index.html
3.- If you manage to solve your problem, please post here your solution.
1.- Post a sample (or samples) of your file please.
2.- Please check here:
http://tavmjong.free.fr/INKSCAPE/MANUAL/html/index.html
3.- If you manage to solve your problem, please post here your solution.
Re: Parsing SVG with an external program in Java
I'm afraid you will not find anything "easier" than batik.
What did you try ?
Did you succeed in displaying a svg into a java UI component ?
http://stackoverflow.com/questions/2611 ... with-batik
when you queried your path you should be able to cast it into a SVGPath
https://xmlgraphics.apache.org/batik/ja ... pport.html
using getPointAtLength you should be able to get the point at (distance) from the start of the path
then you could "insert" a circle at x,y into the document
https://xmlgraphics.apache.org/batik/using/dom-api.html
What did you try ?
Did you succeed in displaying a svg into a java UI component ?
http://stackoverflow.com/questions/2611 ... with-batik
when you queried your path you should be able to cast it into a SVGPath
https://xmlgraphics.apache.org/batik/ja ... pport.html
using getPointAtLength you should be able to get the point at (distance) from the start of the path
then you could "insert" a circle at x,y into the document
https://xmlgraphics.apache.org/batik/using/dom-api.html
-
- Posts: 13
- Joined: Thu Nov 15, 2012 12:14 pm
Re: Parsing SVG with an external program in Java
Hi,
I did not realize that there were javascript libraries for SVG. I am going to try snap.svg. Thank you all for your suggestions and feedback.
-- Craig
I did not realize that there were javascript libraries for SVG. I am going to try snap.svg. Thank you all for your suggestions and feedback.
-- Craig