After setting the background in options to #ffffff, the colour of my canvas is white, it is okay, but the remaining area other than canvas image is transparent, how can I set that remaining area also to a colour e.g a white colour?
You can set backgroundColor
to null
to make it transparent or any color to make the canvas render with the background color
Here, changing the backgroundColor option has effect, but changing it to null creates a black background in the canvas, while there's no black background in my CSS.
I am also getting the canvas render a black background when setting backgroundColor to null
html2canvas(canvasDom, {
allowTaint: true,
useCORS: true,
backgroundColor: "rgba(0,0,0,0)",
removeContainer: true,
x: 0,
y: 0,
width: 374,
height: 722
})
allowTaint: true
with backgroundColor: "rgba(0,0,0,0)"
Solved the problem
I don't think allowTaint
helps in any way with this issue. For me
backgroundColor: 'rgba(0, 0, 0, 0)',
removeContainer: true,
settings were the ones needed.
Most helpful comment
html2canvas(canvasDom, { allowTaint: true, useCORS: true, backgroundColor: "rgba(0,0,0,0)", removeContainer: true, x: 0, y: 0, width: 374, height: 722 })