#javascript #html #css #printing
Вопрос:
Я собираюсь распечатать эту страницу на термопринтере, но высота печатной страницы слишком велика!! как вы можете видеть на этом рисунке, он напечатает очень много белого пространства!!
Я также ограничил html и тело шириной:200 пикселей и высотой:220 пикселей. но все равно высота печати намного больше!
Я использую коды из этой статьи: Распечатайте квитанцию на термопринтере с помощью JavaScript, CSS и HTML
и в статье результат печати просто замечательный! Может быть, это из-за моего принтера??
как я могу печатать только область таблицы без пробелов??
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Receipt example</title>
</head>
<style>
* {
font-size: 12px;
font-family: 'Times New Roman';
}
td,
th,
tr,
table {
border-top: 1px solid black;
border-collapse: collapse;
}
td.description,
th.description {
width: 75px;
max-width: 75px;
}
td.quantity,
th.quantity {
width: 40px;
max-width: 40px;
word-break: break-all;
}
td.price,
th.price {
width: 40px;
max-width: 40px;
word-break: break-all;
}
.centered {
text-align: center;
align-content: center;
}
.ticket {
width: 155px;
max-width: 155px;
}
img {
max-width: inherit;
width: inherit;
}
@media print {
.hidden-print,
.hidden-print * {
display: none !important;
}
}
</style>
<body>
<div class="ticket">
<p class="centered">RECEIPT EXAMPLE
<br>Address line 1
<br>Address line 2</p>
<table>
<thead>
<tr>
<th class="quantity">Q.</th>
<th class="description">Description</th>
<th class="price">$</th>
</tr>
</thead>
<tbody>
<tr>
<td class="quantity">1.00</td>
<td class="description">ARDUINO UNO R3</td>
<td class="price">$25.00</td>
</tr>
<tr>
<td class="quantity">2.00</td>
<td class="description">JAVASCRIPT BOOK</td>
<td class="price">$10.00</td>
</tr>
<tr>
<td class="quantity">1.00</td>
<td class="description">STICKER PACK</td>
<td class="price">$10.00</td>
</tr>
<tr>
<td class="quantity"></td>
<td class="description">TOTAL</td>
<td class="price">$55.00</td>
</tr>
</tbody>
</table>
<p class="centered">Thanks for your purchase!</p>
</div>
<button id="btnPrint" class="hidden-print">Print</button>
<script>
const $btnPrint = document.querySelector("#btnPrint");
$btnPrint.addEventListener("click", () => {
window.print();
});
</script>
</body>
</html>