How can I repeat the page header with jsPDF

0

I'm printing a table with jsPDF + AutoTable and I want the page filter section to always be printed in the header of each page. As the example below is only printed on the 1 page ... ideas?

function printHTML() {  
var doc = new jsPDF('p', 'pt');
var res = doc.autoTableHtmlToJson(document.getElementById("table-content"));

doc.setFontSize(13);
doc.setFontType("bold");
doc.text('header1' , 20, 40);

doc.setFontSize(9);
doc.setFontType("normal");
doc.text('header2', 20, 52);

doc.autoTable(res.columns, res.data, options);

doc.save("table.pdf");
};
    
asked by anonymous 26.02.2018 / 15:53

1 answer

3

To do this you have to create a function with what you want to print from your page. Then you pass the function to the AutoTable plugin.

This should give.

Function printHTML() {

var doc = new jsPDF('p', 'pt');

var res = doc.autoTableHtmlToJson(document.getElementById("table-content"));

var header = function() {

var header1 = document.getElementById("header1").innerHTML;
var header2 = document.getElementById("header2").innerHTML;

doc.setFontSize(13);
doc.setFontType("bold");
doc.text(header1 , 20, 40);

doc.setFontSize(9);
doc.setFontType("normal");
doc.text(header2, 20, 52);

doc.setDrawColor(255,255,255,255);
doc.setLineWidth(2);
doc.line(20, 56, 555, 56); 
};

var options = {
theme: "plain", 
beforePageContent: header,

};

doc.autoTable(res.columns, res.data, options);
doc.save("table.pdf");
}
    
26.02.2018 / 15:59