简体   繁体   English

html2canvas无法获得图像全高

[英]html2canvas doesn't get image full height

For some reason that I can't understand, the html2canvas is not capturing the whole height of the div. 由于某些我无法理解的原因,html2canvas没有捕获div的整个高度。

html2canvas($container, {
    height: $container.height(),
    onrendered: function(canvas) {

        var data = canvas.toDataURL('image/png');           
        var file = dataURLtoBlob(data);

        var formObjects = new FormData();
        formObjects.append('file', file);

        $.ajax({
           url: 'ajax_preview',
           type: 'POST',
           data: formObjects,
           processData: false,
           contentType: false,
        }).done(function(response){
            console.log(response);
            //window.open(response, '_blank');  
        });
    }
});

I have also tried to set up the Height manually height: $container.height() but unfortunately the image keeps getting cut off. 我还尝试设置高度手动height: $container.height()但不幸的是图像不断被切断。 I also tried to set the height 1124, but the result is the same. 我也尝试设置高度1124,但结果是一样的。

It's hard to see, but in the image below you see a white portion of the image without any border. 很难看到,但在下面的图像中,您会看到图像的白色部分没有任何边框。 Everything I have in that portion is not shown. 我在该部分所拥有的一切都没有显示出来。

在此输入图像描述

Any ideas of what could cause this behavior? 有什么可能导致这种行为的想法?

Solved . 解决了

My code is actually right, the problem was on a CSS file that I use. 我的代码实际上是正确的,问题出在我使用的CSS文件上。 To avoid this I've deleted and call again the file while converting the div into an image. 为了避免这种情况,我删除了并在将div转换为图像时再次调用该文件。

// $= means that ends with
("link[href$='my.css']").remove();

html2canvas($container, {
    onrendered: function(canvas) {

        var data = canvas.toDataURL('image/png');           
        var file = dataURLtoBlob(data);

        // etc

        $('head').append("<link href='" + base_url + "public/css/my.css' rel='stylesheet'/>");
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM