How can I repeat the page header with jsPDF

Asked

Viewed 522 times

0

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

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");
};

1 answer

0


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

This should do.

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");
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.