top of page
Writer's pictureSaurabh Singh

Create screenshot from DIV in LWC

There are some ways to take screenshot from div in javascript but in LWC, we need to modify to make it LWC compatible.


First write html as follows



in JS you need to import html2canvas.js. you can download this js from this location.




using printDiv function we can create screenshot and display on the page.

Remember we can display image on Canvas as well, but in my case I was getting blurry images on canvas, so instead on canvas i displayed it on img tag.

5,214 views10 comments

Recent Posts

See All

10 comentarios


Sridhar NareshIT
Sridhar NareshIT
15 dic 2023

Thanks for Making my job very easier , very helpful blog Keep sharing more blogs on salesforce

Me gusta

Nevo Harari
Nevo Harari
03 jul 2023

and Can't see inside the js lib


Me gusta

Nevo Harari
Nevo Harari
03 jul 2023

I also get caught (in promise) Unable to find element in cloned iframe

Me gusta

Souvik Khan
Souvik Khan
04 may 2023

My requirement is kinda same, want to take screenshot/convert lwc component to img/svg format. Using html2canvas as above, it showing this error: caught (in promise) Unable to find element in cloned iframe Any idea?

Me gusta
Tommy
Tommy
07 sept 2023
Contestando a

Also, doesn't work in Chrome for me either. would love if the Author could explain their solution!

Me gusta

Tom Tam
Tom Tam
11 ene 2023

Hi do you have screen shots of this HTML2CANVAS in action on the LWC? When I copy your example I get an error: [0 .default] is not a function


Do you have any recommendations on how to overcome this?

Me gusta
Tommy
Tommy
07 sept 2023
Contestando a

your static resource reference is the same name as the method, change import HTML2CANVAS from '@salesforce/resourceUrl/HTML2CANVAS';


to


import HTML2CANVASref from '@salesforce/resourceUrl/HTML2CANVAS';
and then
loadScript(this, HTML2CANVASref).then(() => {
		console.log('html2canvas loaded');
	});
Me gusta
bottom of page