View Full Version : how to search text and highlight that text area in a svg image using javascript?
saikat
07-19-2012, 02:29 PM
Hello Friends...
I have a project in which I have a SVG image with some text in it. I want to upload this image in my website, so that one can easly search text within the image. I want to use javascript. Can anyone give me some idea that how can search text within the image and highlight the that text area? Also, I want to put a search box on the top of the iamge.
djr33
07-19-2012, 09:51 PM
Is it even possible to manipulate a SVG image using Javascript? I don't think SVG images are well supported in browsers. I know you can view the files (but only the files, not embedded in a webpage) but that often slows down my browser significantly. On wikipedia for example, when they are embedded they are often embedded at a much lower resolution in another format (eg PNG).
I don't have any answer for you (and I honestly wouldn't be surprised if no one here does), but this is an interesting question. Again, though, the first question is whether an SVG image can be manipulated with Javascript. In theory I don't see why not, but I don't know why/if that would be allowed by browsers or included by default.
bernie1227
07-19-2012, 11:32 PM
Unfortunately as Daniel said, this is impossible with JavaScript. The best you can do is convert an svg into a <canvas>.
saikat
08-13-2012, 06:54 AM
Hi dir33 and bernie1227.....
Thank you for your reply and suggestions. Can you please look the website "Wikipathways"? The text search feature within an image in this website is helpful. Same feature I want to give in my website. If you have any idea then please reply to me.
Thanks in advance.
bernie1227
08-13-2012, 08:41 AM
Where on the site is this feature? I would suggest contacting wiki pathways and asking them about it.
keyboard
08-13-2012, 09:05 AM
After a quick google, it looks like you can edit svgs with js...
Using something like this -
var S=document.getElementById("sv")
var SD=S.getSVGDocument();
E=SD.getElementById('E');
E.setAttribute("fill", v);
bernie1227
08-13-2012, 09:14 AM
The problem isn't editing, it's reading.
keyboard
08-13-2012, 09:57 AM
You could create the svg with javascript, then when someone searchs, search the text used to create the svg, highlight it if it's there, then re-write the svg...
It would be tricky, but it should work...
bernie1227
08-13-2012, 10:02 AM
That seems like a lot of hassle, wouldn't you be better off just giving the image a value, and reading the value?
saikat
08-14-2012, 06:02 AM
Thank you everyone......
In my project, I have to read the SVG file and also want to put a serach box, where an user can search a text string. If it will match then the text string would be highlighted. The same feature is avialble in "Inkspace". In Wikipathways this feature is also avialable. There is a search box on the pathway image and an user can search their protein of interest inside the pathway image. Actually I have some images in SVG file format and the text elements are around thousands. So I have to give the search facilty on these images. I am using SVG because the text elements of the images would be dynamic. Therefore, I can't use other file format. Can anybody tell me how to highlight a specific area on an image? Can I use javascript?
saikat
08-14-2012, 06:06 AM
Hi bernie1227.......
I didn't get your suggestion. What did you mean to say the value of an image? Did you mean the coordiante of a particular area on an image?
bernie1227
08-14-2012, 06:55 AM
No that's not what I meant, I meant an actuall value= on the reference to it, but that is only appropriate depending on what you want to do.
keyboard
08-14-2012, 08:33 AM
I've got the working code on my other computer. I'm busy at the moment, but I'll post it tommorow morning for you.
frappierer
12-17-2013, 12:56 PM
I've got the working code on my other computer. I'm busy at the moment, but I'll post it tommorow morning for you.
Hello Keyboard1333,
is that piece of code still alive?
I am working on some reader which uses SVG-XMLs and i need a search and highlight function.
I understood you have something working. Could you share that with me?
Thx
Martin
keyboard
12-18-2013, 02:06 AM
It seems I forgot about this thread ages ago. I'll have a go at rewriting the code and I'll post it later (if somebody doesn't post before me).
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.