Is it possible to use getElementByID to only print a specific element to canvas?
Using the latest version and it will only work with document.body
$("#myButton").click(function () {
html2canvas(document.getElementById('myTable'), {
allowTaint: true,
imageTimeout: 15000,
logging: true,
useCORS: true
}).then(function (canvas) {
document.body.appendChild(canvas);
const b64 = canvas.toDataURL("image/png").replace(/.*,/, '');
console.log("data:image/png;base64, " + b64)
});
});
Maybe your element is scrolled up or down. Try by adding scrollX: -window.scrollX and scrollY: -window.scrollY
$("#myButton").click(function () {
html2canvas(document.getElementById('myTable'), {
allowTaint: true,
imageTimeout: 15000,
logging: true,
useCORS: true,
scrollX: -window.scrollX,
scrollY: -window.scrollY
}).then(function (canvas) {
document.body.appendChild(canvas);
const b64 = canvas.toDataURL("image/png").replace(/.*,/, '');
console.log("data:image/png;base64, " + b64)
});
});
Perfect, that's solved the issue thanks.
Please please please write these two properties to the main examples according to often scrolling while screenshotting. See comment above https://github.com/niklasvh/html2canvas/issues/2368#issuecomment-701920277
scrollX: -window.scrollX,
scrollY: -window.scrollY
Most helpful comment
Maybe your element is scrolled up or down. Try by adding scrollX: -window.scrollX and scrollY: -window.scrollY