Open super-stein opened 5 years ago
Having the same issue with PQGrid.
Having the same issue.
Having same issue
Having same issue
Having same issue
did anyone find solution?
I was having this error, in a different application of canvas and JS, I found out that value which is getting passed to addColorStop method was NaN at some point. So I checked and reset the value to 0 if it was NaN
let ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
if(!percent){
percent = 0
}
let my_gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
my_gradient.addColorStop(percent/100, "rgba(0,0,0,0.1)");
my_gradient.addColorStop(percent/100, EventVars.canvas_bg);
ctx.fillStyle = my_gradient;
ctx.fillRect(0, 0, canvas.width, canvas.height);
same issue
Having the same issue, any solution?
In my case, it had to do with the fact the Canvas was really small, for example, it had width and height of 1 pixel, and also had border of 1. This messed up some of the logic in html2canvas - I think it gets a lineLength of 0 which results in NaN value which leads to this error.
In order to fix this, go to html2canvas.js file in your node modules, search for "createLinearGradient". A line under it, change this:
processColorStops(backgroundImage.stops, lineLength).forEach(function (colorStop) {
To this:
processColorStops(backgroundImage.stops, lineLength || 1).forEach(function (colorStop) {
Make sure to save the changes with patch-package so it persists after npm install.
@Dror-Bar I agree with you. Would you make a PR about it?
While waiting for this project to integrate the awaiting PRs, we released our fork that integrates this solution. You can use it with npm i @cantoo/html2canvas
.
While waiting for this project to integrate the awaiting PRs, we released our fork that integrates this solution. You can use it with
npm i @cantoo/html2canvas
.
This is working for me 🙌., Can i go production with this ?
Bug
We are using the component https://paramquery.com/pro/grid in our application it cause a exception when I try to create a canvas.
Reproduce Bug
//create canvas html2canvas(document.querySelector('body')).then(canvas => {console.log('works')});