简体   繁体   中英

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:

        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.

Now I can understand the width because it is surely wider than the a4 format but why the height too? 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.

How can I fit my element (width and height) inside an A4 format? If I change the value of my body to 800x800 px it works but I would like to achieve it without modifying my HTML.

Thanks

Setting the margins can solve your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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