JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.20/fabric.min.js"></script>
<button id="btn">Save</button>
<a></a>
<canvas id = "abc" width="2400" height="2400" style="width:300px;height:300px;border:solid 2px red"></canvas>
JavaScript
$('#btn').click(function(){
var canvas = new fabric.Canvas('abc');
downloadFabric(canvas,'save');
});
// Download as png
function download(url, name) {
// make the link. set the href and download. emulate dom click
$('a').attr({
href: url,
download: name
})[0].click();
}
function downloadFabric(canvas, name) {
// convert the canvas to a data url and download it.
download(canvas.toDataURL(), name + '.png');
}