简体   繁体   中英

Export multiple DIVs to single pdf

I have page which shows number of tables within a DIV. Those tables have colspan and other attributes. I want to export the whole DIV in a pdf. I was able to do that by using html2pdf library. But it has scaling issues if the data is big and creates more than 17-18 pages, which is known issue of html2pdf library. To resolve that I wanted to break that parent div into two and combine both but that is also not possible. There are libraries which combine pdfs at nodeJS server side. Can someone help me on how to send whole html(containing div and tables) to node(server side) and then create PDF and Save it? Any other solution will also be helpful.

You can simply put a button for downloading the site in pdf like this:

<html>
    <head>
        <style>
            #print_btn{
                cursor:pointer;
            }
        </style>
    </head>
    <body>
        <a id="print_btn">Download PDF</a>
        <script type="text/javascript">
            document.addEventListener("DOMContentLoaded", function() {
                document.getElementById('print_btn').addEventListener('click', function(){
                    if(window.print){
                        window.print();
                    }
                })
            });
        </script>
    </body>
</html>

And with the css @media only print{} rule you can control which elements to hide, or resize.

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