如何使用html2pdf在分页符后添加填充

问题描述 投票:0回答:1

使用html2pdf将vue.js html转换为pdf。在这里一切都很好,我只需要在分页符元素之后添加padding-top和padding-bottom。

这里是我尝试过的代码。

var element = document.getElementById('inner');
            var opt = {
                margin: 0,
                filename: this.auth_user,
                image: {type: 'jpeg',quality: 0.98},
                html2canvas: {
                    scale: 2,
                    bottom: 20
                },
                pagebreak: { mode: ['css']},
                jsPDF: {
                    unit: 'mm',
                    orientation: 'portrait'
                }
            };

            html2pdf().set(opt).from(element).then(function() {
                $("#inner").css( { "font-size":"12px", "background-color" : "#F5F5F5" });
            }).save();

这里需要填充

这里是示例

enter image description here

它将挽救我的一天

javascript pdf jspdf html2canvas html2pdf
1个回答
0
投票

唯一的方法是通过CSS,但是您可以像这样为文档定义边距:

var opt = {
               margin:       [30, 0, 30, 0], //top, left, buttom, right
                filename: this.auth_user,
                image: {type: 'jpeg',quality: 0.98},
                html2canvas: {
                    scale: 2,
                    bottom: 20
                },
                pagebreak: { mode: ['css']},
                jsPDF: {
                    unit: 'mm',
                    orientation: 'portrait'
                }
              };

Fiddle example

© www.soinside.com 2019 - 2024. All rights reserved.