Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank canvas when getting element by ID #2368

Closed
Josh10101010 opened this issue Sep 28, 2020 · 3 comments
Closed

Blank canvas when getting element by ID #2368

Josh10101010 opened this issue Sep 28, 2020 · 3 comments

Comments

@Josh10101010
Copy link

Josh10101010 commented Sep 28, 2020

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)
		});
	});
@nurulalamador
Copy link

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)
		});
	});

@Josh10101010
Copy link
Author

Perfect, that's solved the issue thanks.

@IgorKurkov
Copy link

IgorKurkov commented Dec 4, 2020

Please please please write these two properties to the main examples according to often scrolling while screenshotting. See comment above #2368 (comment)

scrollX: -window.scrollX,
scrollY: -window.scrollY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants