Welcome Guest Search | Active Topics | Sign In | Register

EO.Webbrowser: all svg's in DOM to files on disk Options
jrk
Posted: Tuesday, January 21, 2020 2:41:40 PM
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.
eo_support
Posted: Tuesday, January 21, 2020 4:14:52 PM
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!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.