eKoopmans / html2pdf.js

Client-side HTML-to-PDF rendering using pure JS.
MIT License
4.13k stars 1.39k forks source link

html2pdf.js : header and footer are not showing on every page #526

Open ghost opened 2 years ago

ghost commented 2 years ago

I have a header and footer in my Html element ID I want to print that on every page of the pdf

ghost commented 2 years ago

var element = document.getElementById('order-table');

ghost commented 2 years ago

In this order table i have header and footer i want to print that on every page of pdf

ghost commented 2 years ago

By using this html2pdf.js

ghost commented 2 years ago

if from this library it can't achieve please suggest something

RizTyagi commented 2 years ago

@ghost try this

 var header = document.getElementById('HeaderId');
  html2pdf().from(header ).toImg().get('img').then(function (img) {          
                html2pdf().from(element).toPdf().get('pdf').then(function (pdf) {            
                                       var totalPages = pdf.internal.getNumberOfPages();
                                   for (var i = 1; i <= totalPages; i++) {
                                             pdf.setPage(i);
                            if (i != 1) {
                                pdf.addImage(img, 'JPEG', 6, 0, pdf.internal.pageSize.getWidth() - 12, 0);
                            }
                            pdf.text(30, pdf.internal.pageSize.getHeight() - 1, 'FooterText');
                         }).get('pdf').save()
jowmm commented 2 years ago

@RizTyagi tried this but the footer is still not showing. Is there any updates on how to put the header and footer on the pdf?