Rasel Ahmed
Rasel Ahmed

Reputation: 1

How to add padding after page break using html2pdf

Converting vue.js html to pdf using html2pdf. Here everything is fine, Only thing i need to add padding-top and padding-bottom after pagebreak elements.

Here is code that I tried.

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();

And here need padding

Here is the sample

enter image description here

It will save my day

Upvotes: 0

Views: 15487

Answers (1)

Ivan Ferrer
Ivan Ferrer

Reputation: 578

The only way to fill it out is through CSS, but you can define a margin for your document like this:

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

Upvotes: 0

Related Questions