<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <style type="text/css"> /*@media screen print 'print' not working for print preview { }*/ table.splitForPrint { width:681 ; /*assuming 816px for Letter size minus 1.5in margin or approx 135px*/ border: solid 1px #000000;border-bottom: 0; /*turn off bottom since last row will have bottom border*/border-collapse: collapse; font-family: sans-serif;font-style: normal; font-weight: normal;font-size: 12px; } table.splitForPrint td {width:227/*Must divide total width by columns*/; border-bottom: solid 1px #000000;padding:4px;} table.splitForPrint th {border-bottom: solid 1px #000000; background-color: "AliceBlue";padding:4px;} </style> <script src="jquery-1.7.1.min.js"></script> <script type="text/javascript"> //adapted from http://code.google.com/p/wkhtmltopdf/issues/detail?id=168 $(document).ready(function () { $('table.splitForPrint').each(function(i, tabela){ // this to set 'this' context to table var trlength = $('tbody tr', tabela).length; //850:assuming 8.85 in. reserved for tbl height based on 96DPI(http://auctionrepair.com/pixels.html) var maxtrpxperpage = 950; var trsleft = trlength; var pageno = 1; var ultimo = $(tabela); //$('table.splitForPrint').first(); while (trsleft > 0) { var copy = ultimo.clone(); var debugmessage = "<br>starting while loop<br>"; var numtrsremovedfromcurrent = 0; var curtrscount = $('tbody tr', copy).length; var curtbltrscount = 0; //get in reverse order $($('tbody tr', ultimo).get().reverse()).each(function(i, tr){ if (ultimo.height() > maxtrpxperpage) { $(tr).remove(); numtrsremovedfromcurrent++; } else { return false; } }); curtbltrscount = curtrscount - numtrsremovedfromcurrent; $('tbody tr', copy).each(function(i, tr){ if (i < curtbltrscount) { $(tr).remove(); } }); if (copy.find("td").length > 0) //don't insert a table with only a header { copy.insertAfter(ultimo); $("<div style='page-break-before:always'>Page " + (++pageno) + "</div>").insertAfter(ultimo); /* var heights = $.map( ultimo.find("tr"), function(el){ return $(el).outerHeight() + "|" + $(el).find("td").eq(1).text() + "/" + $(el).find("td").height() }).join(", "); $("<div style='font-family: sans-serif;font-size:15px;page-break-before:always'>blosah" + trlength + ", heights: " + heights + "<br>debugmsg: " + debugmessage + "--trs:" + ultimo.find("tr").length + "; window height: " + $(window).height() + "; document height: " + $(document).height() + "; table height: " + ultimo.height() + "; table width: " + ultimo.width() + "</div>").insertAfter(ultimo); */ } //copy.css('page-break-before', 'always'); ultimo = copy; trsleft -= curtbltrscount; } }); }); </script> </head> <body> <table class="splitForPrint" ><thead><tr><th>Header1###<th>Header2</th><th>Another header here</th></tr></thead> <tbody> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> </tbody></table> </body>
Friday, September 28, 2012
Printing Paginated HTML Page
Update: To just prevent new page on TR breaks add the following style (Note the DOCTYPE!):
<!DOCTYPE html>
<!-- saved from url=(0016)http://localhost -->
<html><head>
<style type="text/css">
@media print
{
tr {page-break-inside:avoid}
}
</style>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment