简体   繁体   English

将多个DIV导出为单个pdf

[英]Export multiple DIVs to single pdf

I have page which shows number of tables within a DIV. 我有显示DIV中表格数量的页面。 Those tables have colspan and other attributes. 这些表具有colspan和其他属性。 I want to export the whole DIV in a pdf. 我想将整个DIV导出为pdf。 I was able to do that by using html2pdf library. 通过使用html2pdf库,我能够做到这一点。 But it has scaling issues if the data is big and creates more than 17-18 pages, which is known issue of html2pdf library. 但是,如果数据很大并且创建的页面超过17-18页,则会出现缩放问题,这是html2pdf库的已知问题。 To resolve that I wanted to break that parent div into two and combine both but that is also not possible. 为了解决这个问题,我想将该父div分为两部分并结合起来,但这也是不可能的。 There are libraries which combine pdfs at nodeJS server side. 在nodeJS服务器端有一些库结合了pdf。 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? 有人可以帮我如何将整个html(包含div和表)发送到node(服务器端),然后创建PDF并保存吗? Any other solution will also be helpful. 任何其他解决方案也将有所帮助。

You can simply put a button for downloading the site in pdf like this: 您可以简单地按下一个按钮,以pdf格式下载网站:

<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. 使用css @media only print{}规则,您可以控制要隐藏或调整大小的元素。

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

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