niklasvh / html2canvas

Screenshots with JavaScript
https://html2canvas.hertzen.com/
MIT License
30.61k stars 4.81k forks source link

html2Canvas - Returned canvas is empty Ionic 4 #1829

Open bkarv opened 5 years ago

bkarv commented 5 years ago

Please make sure you are testing with the latest release of html2canvas. Old versions are not supported and issues reported for them will be closed.

Please follow the general troubleshooting steps first:

Bug reports:

i am trying to implement html2Canvas v 1.0.0-rc.1 in my Angular 7/Ionic 4 project.

The issue I have is when I try to get the canvas of a simple div, the return canvas is emptied and nothing is appended to my destination div using *.appendChild as per the documentation.

For debugging I console log the return canvas where it looks like this:

<canvas width="0" height="0" style="width: 0px; height: 0px;"></canvas>

Below is my code and console logs. I've tested in Safari 12 and Chrome 74. What am I doing wrong? Thanks in advance

HTML


<div id="destination">
  Destination - Html Canvas to Append to This
</div>
<div id="cover">
    Source - Hello World
</div>

Javascript/Component

printTest(): void {
    let element = document.getElementById("cover");
    console.log('Source Element', element);
    html2canvas(element).then((canvas) =>{
      console.log('Console Canvas', canvas)
      var destination = document.getElementById('destination');
      destination.appendChild(canvas);
    });
}

Console Logs

Screen Shot 2019-05-03 at 6 43 07 pm

Specifications:

Ionic:

   ionic (Ionic CLI)             : 4.12.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.3.0
   @angular-devkit/build-angular : 0.13.8
   @angular-devkit/schematics    : 7.2.1
   @angular/cli                  : 7.3.8
   @ionic/angular-toolkit        : 1.2.0

Cordova:

   cordova (Cordova CLI) : 7.1.0
   Cordova Platforms     : browser 5.0.4
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 9 other plugins)

System:

   ios-deploy : 1.9.1
   NodeJS     : v10.10.0 (/usr/local/bin/node)
   npm        : 6.7.0
   OS         : macOS Mojave
hakimio commented 5 years ago

Is the data loaded and all the animations finished at the time you are calling html2canvas?

ghost commented 5 years ago

See https://stackoverflow.com/questions/54691069/ionic-4-html2canvas/55853462#55853462 It works for me too.

Snowbases commented 5 years ago

I got the same problem

See https://stackoverflow.com/questions/54691069/ionic-4-html2canvas/55853462#55853462 It works for me too.

I got the same problem, but it doesnt fix the problem, i dont know why, i tried many method but didnt successfully