JsPDF Multiple page data is getting cropped

跟風遠走 提交于 2021-01-29 21:10:47

问题


The code that I have used for creating PDF s given below and my requirement is to make the PDF content not select (it should be like a Image) , that I have achieved. Now my problem is when the content in PDF is more it will generate in second page but there is no padding in bottom and header part.

I have tried various options like autoTableHtmlToJson and many but of no positive result .

                   html2canvas($('#mydiv')[0]).then(canvas => {
                        try {
                             contentH = $('#mydiv').height();
                             var img = canvas.toDataURL("image/png", 1.0);
                             $w = $actw = canvas.width;
                             $h = $acth = canvas.height;
                             var pdf = new jsPDF("p", "mm", "Letter");
                             var width = $maxw = pdf.internal.pageSize.width;
                             var height = $maxh = pdf.internal.pageSize.height;
                             if (!$maxw) $maxw = width;
                             if (!$maxh) $maxh = height;
                             if ($w > $maxw) {
                              $w = $maxw;
                              $h = Math.round($acth / $actw * $maxw);
                              }
                              pdf.addImage(img, 'JPEG', 0, 0, $w, $h);
                              $count = Math.ceil($h / $maxh) - 1;
                              $count = Math.ceil($h / $maxh) - 1;
                              for (var i = 1; i <= $count; i++) {
                              position = - $maxh * i
                              //pdf.text(10, 20, 'Hello World');
                              pdf.addPage(img, 'JPEG', 0, 0, $w, $h);
                              pdf.addImage(img, 'JPEG', 0, position, $w, $h);
                              }
                             pdf.save("file.pdf");
                              } catch (e) {
                              alert("Error description: " + e.message);
                              }
                             });

I need to add padding at bottom of first page and header of second page (there can also be multiple pages), I have attached the image for reference .

Hope somebody can help me ,thanks in advance

来源:https://stackoverflow.com/questions/63378768/jspdf-multiple-page-data-is-getting-cropped

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!