Html2Canvas ASP.NET Core

0

I'm trying to add the html2canvas on my ASP.NET Core web site.

In documentation , they say to use:

npm install html2canvas

When I run this command, html2canvas is installed on:

myproject/src/myproject/node_modules

When I try to use the html2canvas methods, the following error occurs in the browser console:

html2canvas is not defined

So I manually added the html2canvas.js file to my project and referenced it on the html page. html2canvas is not defined no longer appeared, but the page is not rendered correctly using the html2canvas commands.

var element = document.getElementById("divPrint");

html2canvas(element).then(function(canvas) {
    // Export the canvas to its data URI representation
    var base64image = canvas.toDataURL("image/png");

    // Open the image in a new window
    window.open(base64image , "_blank");
});

What is the correct way to install? Via npm or just adding the file .js ?

Could anyone explain?

    
asked by anonymous 09.03.2018 / 13:15

1 answer

0

Considering that you are only using NPM, there are some possibilities for using the downloaded packages.

It's good to note that downloading packages is just one of the tasks NPM offers to optimize repetitive tasks when creating a website.

Come on:

  • copy the compiled file (s) into your sources (many packages come with the creation, test and distribution files)
  • Make a direct link to the compiled file, in your example it would look something like
  • <script src="../node_modules/html2canvas/html2canvas.js"></script>

    Both approaches work, but see which one is best when you want to upgrade packages.

        
    18.03.2018 / 19:45