Skip to content
Advertisement

How to pass HTML to JPG/PNG? In Javascript/Typescript

How can i convert an HTML to a JPG/PNG image? I already tried various options but none works for me, they only make the image of some parts of the HTML.

Example with html2canvas:

TS

JavaScript

HTML

JavaScript

This error I get when I use the example: enter image description here

“DOMException: Failed to set the ‘adoptedStyleSheets’ property on ‘ShadowRoot’: Sharing constructed stylesheets in multiple documents is not allowed”

Do you know any other tools? Basically I need to take a screenshot of only a part of my screen not the full screen. Any ideas?

Advertisement

Answer

You can use the package: https://www.npmjs.com/package/dom-to-image

In your page:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement