I
I
im_sama2021-09-26 14:52:19
JavaScript
im_sama, 2021-09-26 14:52:19

How to get image from canvas?

I'm using html2canvas to take a screenshot of a page.
I need to send the received screen to the server.
I wrote the following. code

html2canvas(document.getElementById('ForPdf'), {
allowTaint: true,
backgroundColor: 'transparent',
useCORS: true,
}).then(
function (canvas) {
let previewButton = document.querySelector('.modal-connection- prices__btn'),
imgageData = canvas.toDataURL("image/png");
/* imgageData = imgageData.replace(/^data:image\/png/, "data:application/octet-stream"); ​​*/
previewButton. removeAttribute('disabled');
previewButton.addEventListener('click', function () {
document.getElementById('ForPdf').appendChild(canvas);
});
}
);

Here the screenshot is formed and entered into the canvas (I display it after the content). But I can't get an image from there.
toDataURL doesn't work. I displayed everything possible in the console, an empty string is displayed (no url).

Tell me what could be the problem or how else can I get an image from canvas.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question