简体   繁体   English

html2pdf 和 html2canvas 返回空白页

[英]html2pdf and html2canvas returnin blank page

I am trying to export a body element of my page in pdf then print it, the element size (width and height) I checked and they are bigger than my A4 format I want to export, here is the code:我正在尝试在 pdf 中导出我的页面的正文元素,然后打印它,我检查的元素大小(宽度和高度)比我要导出的 A4 格式大,这里是代码:

        var filename;
        var element = document.getElementsByTagName("BODY")[0];
        if (Object.keys(Chart.instances).length > 0) {
            filename = "Report_chart_" + $("#DDlQqtp option:selected").text().replace(/ /g, "_") + ".pdf";
        } else {
            filename = "Report_test" + $("#DDlQtp option:selected").text().replace(/ /g, "_") + ".pdf";
        }
        var options = {
            filename: filename,
            image: { type: 'jpeg', quality: 1 },
            jsPDF: { unit: 'pt', format: 'a4', orientation: 'l' }
        };
        html2pdf().set(options).from(element).save();

but the width is getting cut, I can't see the last column of my table inside the body and after 2 pages it is starting to give blank pages.但是宽度正在减少,我在正文中看不到表格的最后一列,并且在 2 页之后它开始给出空白页。

Now I can understand the width because it is surely wider than the a4 format but why the height too?现在我可以理解宽度了,因为它肯定比 a4 格式更宽,但为什么还要高度呢? It should simply go to another page instead its like is trying to export my pdf giving to it the same height of my body and once it surpassed it starts giving blank pages.它应该只是 go 到另一个页面,而不是它试图导出我的 pdf 给它我的身体相同的高度,一旦它超过它就开始给出空白页。

How can I fit my element (width and height) inside an A4 format?如何将我的元素(宽度和高度)放入 A4 格式? If I change the value of my body to 800x800 px it works but I would like to achieve it without modifying my HTML.如果我将身体的值更改为 800x800 像素,它可以工作,但我想在不修改 HTML 的情况下实现它。

Thanks谢谢

Setting the margins can solve your problem设置边距可以解决您的问题

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

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