I spent several hours searching for a solution located in the jsPDF library, but it does not seem to be available at the moment. Once you specify pageplit, it seems to ignore other jsPDF options such as margin.
SO, I did it myself, breaking the pages manually. It is actually relatively simple. :)
I created this for a large table. If you are trying to split something other than a table, you can still use this concept. All you really need to do is change the CSS classes to make the different parts visible.
function add_page() { // Youre header & footer stuff goes here pdf.addHTML($('#pdfPage'), 20, 26, options, function() { check_page(); }); } function check_page() { tr_rows = tr_rows - 28; if( tr_rows > 0 ) { $('#pdfPage').removeClass('pdf_page_' + current_pdf_page).addClass('pdf_page_' + ++current_pdf_page); pdf.addPage(); add_page(); } else { pdf.save( filename + '.pdf' ); } } $('#pdfPage').addClass('pdf_page_1'); tr_rows = $('#pdfPage tbody tr').length; current_pdf_page = 1; add_page();
And here are my CSS classes:
.pdf_page_1 tr:nth-child(n+28) { display: none; } .pdf_page_2 tr:nth-child(-n+28) { display: none; } .pdf_page_2 tr:nth-child(n+56) { display: none; } .pdf_page_3 tr:nth-child(-n+56) { display: none; } .pdf_page_3 tr:nth-child(n+84) { display: none; } .pdf_page_4 tr:nth-child(-n+84) { display: none; } .pdf_page_4 tr:nth-child(n+112) { display: none; } #pdfPage tr:first-child { display: table-row !important; }
source share