On Mon, Jul 17, 2017 at 3:13 PM, Per Newgro <[email protected]> wrote:
> Thanks for your response Martin.
>
> I tried to make it work the whole day now. But i can not get it to work
> with IE11.
> There is always a security error. This is a known problem for IE and
> canvas.
>
> I ended up:
>
> $("#chart-export").on("click", function() {
> var svg = document.querySelector( "svg" );
> var svgData = new XMLSerializer().serializeToString( svg );
>
> var canvas = document.createElement( "canvas" );
> document.body.appendChild(canvas);
> var svgSize = svg.getBoundingClientRect();
> canvas.width = svgSize.width;
> canvas.height = svgSize.height;
>
> var ctx = canvas.getContext( "2d" );
> ctx.clearRect(0, 0, canvas.width, canvas.height);
>
> var img = document.createElement("img");
> img.setAttribute("crossOrigin", "anonymous");
> img.onload = function() {
> ctx.drawImage( img, 0, 0 );
> var a = document.createElement("a");
> a.download = "chart.png";
> a.href = canvas.toDataURL( "image/png" );
> document.body.appendChild(a);
> a.click();
> };
> img.setAttribute("src", "data:image/svg+xml;base64," +
> btoa(unescape(encodeURIComponent(svgData)))
> );
> });
>
> So i need to go on the other way. But there my problems still occur.
>
What exactly are the problems ?
It is not very clear from your first email.
>
> Regards
> Per
>
> > Gesendet: Montag, 17. Juli 2017 um 10:42 Uhr
> > Von: "Martin Grigorov" <[email protected]>
> > An: "[email protected]" <[email protected]>
> > Betreff: Re: Use Resource to transfer SVG to PNG
> >
> > Hi,
> >
> > Wouldn't HTML Canvas API be better solution?
> > See https://stackoverflow.com/a/27232525/497381
> >
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Mon, Jul 17, 2017 at 10:12 AM, Per Newgro <[email protected]> wrote:
> >
> > > Hello *,
> > >
> > > I would like to generate a png from a svg. The transcoding is done by
> > > using Batik.
> > > So far it works as expected.
> > >
> > > But i'm not sure how to provide the resulting png (a byte[]) to my
> > > frontend.
> > >
> > > The svg is generate in browser by using highcharts. I would like to
> > > provide a button
> > > that downloads the transcoded png by sending a request to the
> "transcoding
> > > resource"
> > > and using the svg-dom from browser.
> > >
> > > Is there someone who did that already once? Can you please give me a
> hint
> > > how this could work?
> > >
> > > Thanks for your support
> > > Per
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [email protected]
> > > For additional commands, e-mail: [email protected]
> > >
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>