0

I am trying to create a ReactJS-App using FabricJS canvas. For a test I created simple SVG shapes and add them to a canvas. I wand to download them as a .png and for that I use a button.

I use the arrow-function thing instead of .bind() for the method.

The following code is the part that creates the png and downloads it. It works in Chrome but not in Firefox.

import React from 'react';
import {fabric} from 'fabric';
import {Button} from 'react-bootstrap';


class FabricCanvas extends React.Component{

//Code for adding elements to canvas omitted

    saveToCanvas = () => {

        var link = document.createElement("a");
        link.href = this.the_canvas.toDataURL({format: 'png'});
        link.download = "avatar.png";
        link.click();

    }

    render(){

        return (
            <React.Fragment>
                <canvas id='main-canvas'>
                </canvas>
                <Button className='large success' onClick={this.saveToCanvas} >
                    Download
                </Button>
            </React.Fragment>
        );
    }
}
  • Do you get any console errors? – Chris Ngo Oct 09 '19 at 23:47
  • @ChristopherNgo none concerning this function. –  Oct 10 '19 at 00:01
  • Possibly related to how `toDataURL` works on firefox. Check: https://stackoverflow.com/questions/32326943/canvas-todataurlimage-png-not-working-properly-in-firefox – Jackyef Oct 10 '19 at 03:00
  • @Jackyef I don't understand these answers how they apply to my issue. Can you please explain? I am not putting a data base64 into a img tag but want to give a download –  Oct 11 '19 at 12:30

0 Answers0