I am currently working with a canvas element using Fabric.JS. Beneath the canvas on the screen, there is a textarea
within the DOM.
The download button on the page successfully downloads the canvas
element as an image. However, I now need to include the text from the textarea
in the downloaded image, positioned below the canvas.
I am unsure of how to achieve this. Can someone provide guidance on how this can be implemented?
Below is the code snippet (written in TypeScript and used in a React application), but regardless of the specifics, the concept should remain the same even if it were pure JavaScript - create a dummy 'a' element and trigger a click event:
const url = canvas.toDataURL({
format: "png",
width,
height,
});
const a = document.createElement("a");
a.href = url;
a.download = "download";;
const clickHandler = () => {
setTimeout(() => {
URL.revokeObjectURL(url);
a.removeEventListener("click", clickHandler);
a.remove();
}, 150);
};
a.addEventListener("click", clickHandler, false);
a.click();