Rank: Newbie Groups: Member
Joined: 8/21/2018 Posts: 5
|
I'm pretty new to your product, and I've used from a very basic context...building a URL, requesting URL, trapping LoadComplete and using JSExtInvoke to trap a call from the web server to run .Net code.
What I now need to do is allow user to pull all svg elements from the DOM and for each, dump svg to a .png file on disk. I have some javascript that will walk through the DOM for all svg's, and for each, convert to base64 (although I'm no java scripting professional). I'm assuming I can run this javascript using EvalScript, where this might return the resultant base64 to .Net where I can further use a file writer to dump to a .png on disk?
Javascript would be something to the effect of:
function svgToBase64(svgIn){ var xml = new XMLSerializer().serializeToString(svgIn) var svg64 = btoa(xml); //for utf8: btoa(unescape(encodeURIComponent(xml))) var b64start = 'data:image/svg+xml;base64,'; var image64 = b64start + svg64; return image64; };
function walkThroughDom() { svg = document.getElementsByTagName("svg"); for (var i = 0; i < svg.length; i++) { var svgBase64 = svgToBase64(svg[i]);
//return svgBase64; } }; walkThroughDom()
Any examples or guidance on best practice using EO.Webbrowser would sincerely appreciated.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Hi, You can simply return the value from your JavaScript function. So for example, if you have a JavaScript function like getSVGInBase64(svg_id), then you can just call
Code: C#
string svg1InBase64 = WebView.EvalScript("getSVGInBase64('svg1');") as string;
If you want needs to return multiple values, you can concat them into a single string with a special separator on the JavaScript side and then split them into multiple value on the .NET side, or simply return an array from your JavaScript function. Thanks!
|