Tengo una tabla con varias columnas.Imprime una tabla HTML muy amplia sin recorte en el lado derecho
el problema específico
Al imprimir dicha tabla, las columnas de la derecha no se imprimirán, ni siquiera cuando se imprime en orientación horizontal.
el comportamiento deseado
El navegador debe imprimir toda la tabla, utilice varias hojas si es necesario. Las soluciones de CSS/JavaScript son aceptables.
CÓDIGO menor tiempo necesario para reproducir el problema
Haga clic en el botón de impresión en la siguiente demostración. Mire el lado derecho de la página en la ventana de vista previa de impresión.
$(function() {
$("input:first").click(function() {
window.print();
});
$(".description").each(function() {
var text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla placerat malesuada sodales. Nulla convallis neque lorem, ac varius enim. Ut dapibus, orci at feugiat eleifend, dui mi lobortis tortor, ac egestas neque enim et neque. Donec tempus mi quis tellus dapibus eu blandit magna sagittis. Curabitur ac ultrices tortor. Aliquam id tincidunt urna. Nunc id neque ac urna congue convallis. Etiam eget massa vitae justo aliquam pulvinar vitae ut diam.";
text = text.substr(0, Math.ceil(Math.random() * 100));
$(this).text(text);
});
$(".number").each(function() {
var text = (Math.random() * 1000).toFixed(2);
$(this).text(text);
});
});
@media screen {
input {
width: 100%;
margin: 1em 0;
}
}
@media print {
input {
display: none;
}
}
th {
font: bold 12px sans-serif;
border: 1px solid;
white-space: nowrap;
}
td {
font: 12px sans-serif;
border: 1px dotted;
}
td.description {
min-width: 200px;
border-style: solid;
}
td.number {
padding-left: 20px;
text-align: right;
border-style: solid;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input type="button" value="Print">
<table>
<tr>
<td></td>
<td></td>
<th colspan="12">2009</th>
<th colspan="12">2010</th>
<td></td>
</tr>
<tr>
<td></td>
<th>Description</th>
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
<th>Apr</th>
<th>May</th>
<th>Jun</th>
<th>Jul</th>
<th>Aug</th>
<th>Sep</th>
<th>Oct</th>
<th>Nov</th>
<th>Dec</th>
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
<th>Apr</th>
<th>May</th>
<th>Jun</th>
<th>Jul</th>
<th>Aug</th>
<th>Sep</th>
<th>Oct</th>
<th>Nov</th>
<th>Dec</th>
<th>Total</th>
</tr>
<tr>
<th rowspan="2">Batch number 1</th>
<td rowspan="2" class="description"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<th rowspan="4">Batch number 2</th>
<td rowspan="4" class="description"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<th rowspan="4">Batch number 3</th>
<td rowspan="4" class="description"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<th rowspan="2">Batch number 4</th>
<td rowspan="2" class="description"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<th>Total</th>
<td class="description"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
</table>
Prueba este de impresión @media {@ Page {size: paisaje}} [Esto ayudará a] [1] [1]: http://stackoverflow.com/questions/138422/landscape-printing-from-html – Narek
Si leyó la pregunta, _even_ landscape orientation no ayuda. Según entiendo la pregunta, es si puede hacer que el navegador imprima un contenido muy amplio en varias páginas, por lo que sé que no puede. – OlliM
esto no es un "¿por qué no está funcionando este código?" pregunta, certanly pregunta "Cómo", a un tema específico, y le dice qué OP investigar e intentar –