function test() {
  var element = document.getElementById('root');
  // Generate the PDF.
  html2pdf().from(element).set({
  margin:       [0, 0, 0, 0],
    filename: 'samplepdf.pdf',
   pageBreak: { mode: 'css', before:'#nextpage1'},
    jsPDF: {orientation: 'landscape', unit: 'in', format: 'letter'}
  }).toPdf().get('pdf').then(function (pdf) {
    var totalPages = pdf.internal.getNumberOfPages();
 
    for (i = 1; i <= totalPages; i++) {
     pdf.setPage(i);
      pdf.setFontSize(10);
      pdf.setTextColor(150);
    pdf.text( i + '/' + totalPages, (pdf.internal.pageSize.getWidth()/2.25), (pdf.internal.pageSize.getHeight()-8));
      
    
      }
  }).save();
}
 
document.getElementById('btnPrint').onclick = test;