I have table tag html where the tr and td is loop by array. I need to print the table with specific size paper. i already using :
@page {
size: A4;
margin: 0;
}
@media print {
html,
body {
width: 16cm;
height: 21cm;
}
}
But, i have many data to loop, so it still print like more than size of html.
i need to print only 4 row and 3 column every paper so only total 1 one paper 12 column. could you help me to make only print in 12 column?
I have table tag html where the tr and td is loop by array. I need to print the table with specific size paper. i already using :
@page {
size: A4;
margin: 0;
}
@media print {
html,
body {
width: 16cm;
height: 21cm;
}
}
But, i have many data to loop, so it still print like more than size of html.
i need to print only 4 row and 3 column every paper so only total 1 one paper 12 column. could you help me to make only print in 12 column?
Share Improve this question asked 12 hours ago user3505775user3505775 3372 gold badges6 silver badges20 bronze badges 5 |2 Answers
Reset to default 0Not using <table>
at all is a good advice. Or use it only in the way that each line is a table on its own, with just one single row.
PD4ML will then do the pagination properly.
Save this snippet in HTML file. It worked for me as local HTML file. (Error with snipped demo).
function print_list(){
var eachPageMaxCol=3;
var eachPageMaxRow=4;
var x=document.getElementsByClassName("printObject");
var l=x.length;
var rowConter=0;
var res="";
res+="<div align='center'><table border='1' style='break-after: page;'>";
for(var cnt=0;cnt<l;cnt++){
res+="<tr>";
for(let c=0;c<eachPageMaxCol && cnt<l;c++,cnt++){
res+="<td align='center' style='min-width:140px;height:40px;'>"+x[cnt].innerHTML+"</td>";
}
res+="</tr>";
if(cnt>=l){res+="</table>";break;}
else if(++rowConter>=eachPageMaxRow){rowConter=0;res+="</table>"+"</br></br></br></br>"+"<table border='1' style='break-after: page;'>";}
cnt--;
}
var printdlg = window.open('', 'PRINT', 'height=400,width=400');
printdlg.document.write(res);
printdlg.document.close();
printdlg.focus();
printdlg.print();
printdlg.close();
}
<body>
<table border='1'>
<tr>
<td align='center' class='cellcls printObject'>0</td>
<td align='center' class='cellcls printObject'>1</td>
<td align='center' class='cellcls printObject'>2</td>
</tr>
<tr>
<td align='center' class='cellcls printObject'>3</td>
<td align='center' class='cellcls printObject'>4</td>
<td align='center' class='cellcls printObject'>5</td>
</tr>
<tr>
<td align='center' class='cellcls printObject'>6</td>
<td align='center' class='cellcls printObject'>7</td>
<td align='center' class='cellcls printObject'>8</td>
</tr>
<tr>
<td align='center' class='cellcls printObject'>9</td>
<td align='center' class='cellcls printObject'>10</td>
<td align='center' class='cellcls printObject'>11</td>
</tr>
<tr>
<td align='center' class='cellcls printObject'>12</td>
<td align='center' class='cellcls printObject'>13</td>
<td align='center' class='cellcls printObject'>14</td>
</tr>
<tr>
<td align='center' class='cellcls printObject'>15</td>
<td align='center' class='cellcls printObject'>16</td>
</tr>
</table>
<button onclick="print_list();"/>print</button>
</body>
break-after
to break the page after the desired line. – mr mcwolf Commented 10 hours agotable
because it will be difficult to modify the table if you are displaying the content on mobile devices. – mr mcwolf Commented 6 hours agobreak-after
applies to block-level elements only - whichtd
are not. – C3roe Commented 5 hours ago