как добавить нижний колонтитул html2pdf.js

#html2pdf

Вопрос:

Подскажите, как добавить нижний колонтитул на каждую страницу с помощью html2pdf.js [рабочая версия][1]

   function test() {
    // Get the element.
    var element = document.getElementById('the-document');




    // Generate the PDF.
    html2pdf().from(element).set({
      filename:  'test.pdf',
      image: {type: 'jpeg',quality: 1.0},
            html2canvas: {dpi: 75, scale: 2, letterRendering: true},
      pagebreak: { mode: ['avoid-all', 'css', 'legacy'] },
      jsPDF: {orientation: 'portrait', unit: 'in', format: 'a4', compressPDF: true},
      // pdfCallback: pdfCallback
    }).save();

  } 

Ответ №1:

Попробуйте сделать следующее:

 // config from your example
const config = {
      filename:  'test.pdf',
      image: {type: 'jpeg',quality: 1.0},
      html2canvas: {dpi: 75, scale: 2, letterRendering: true},
      pagebreak: { mode: ['avoid-all', 'css', 'legacy'] },
      jsPDF: {orientation: 'portrait', unit: 'in', format: 'a4', compressPDF: true},
      // pdfCallback: pdfCallback
    }

 html2pdf().from(content).set(config).toPdf().get('pdf').then((pdf) => {
    var totalPages = pdf.internal.getNumberOfPages();

    for (let i = 1; i <= totalPages; i  ) {
      // set footer to every page
      pdf.setPage(i);
      // set footer font
      pdf.setFontSize(10);
      pdf.setTextColor(150);
      // this example gets internal pageSize just as an example to locate your text near the borders in case you want to do something like "Page 3 out of 4"
      pdf.text(pdf.internal.pageSize.getWidth() - 30,                
        pdf.internal.pageSize.getHeight() - 10, 'YOUR TEXT GOES HERE!');

       // you can add the line separator as an image, consult the docs below to properly set the place of the image
      pdf.addImage(img, 'png', 0, 0, 52, 23)
    }
   
  }).save();

  this.elementPDF.clear();

}
 

Вы можете проверить всю документацию по этим методам jsPDF здесь: https://artskydj.github.io/jsPDF/docs/module-addImage.html !