如何在打印我的
div
时从打印输出中删除不需要的空白。我必须打印 DIV 的内容,例如 POS
收据,但它在顶部和底部有额外的空白,我只想打印 div
内容。
@media print {
@page {
size: 100mm 150mm;
}
}
<div>
<center>
<div>Job Sheet</div>
<h2>
<b>My Company Name</b>
<br/>
<small>My Address here</small><br/>
<small>1234567890, 1234567890</small><br/>
</h2>
<hr/>
<table align="center">
<tr>
<td class="printHeading"><b>Date: </b></td>
<td id="date1" class="printHeading">000-00-00 00:00:00</td>
</tr>
<tr>
<td class="printHeading"><b>Job No: </b></td>
<td id="caseid1" class="printHeading">fgnfg</td>
</tr>
<tr>
<td class="printHeading"><b>Name: </b></td>
<td id="name1" class="printHeading">fgnfgn</td>
</tr>
<tr>
<td class="printHeading"><b>Address: </b></td>
<td id="address1" class="printHeading">fgnfg</td>
</tr>
<tr>
<td class="printHeading"><b>Mobile: </b></td>
<td id="mobile1" class="printHeading">fgnfg</td>
</tr>
<tr>
<td class="printHeading"><b>Brand: </b></td>
<td id="brand1" class="printHeading">fgnfgn</td>
</tr>
<tr>
<td class="printHeading"><b>Model: </b></td>
<td id="model1" class="printHeading">fgsfg</td>
</tr>
<tr>
<td class="printHeading"><b>IMEI Number: </b></td>
<td id="imei_number1" class="printHeading">75375732</td>
</tr>
<tr>
<td class="printHeading"><b>Problem: </b></td>
<td id="problem1" class="printHeading">fgjdfgdfg</td>
</tr>
<tr>
<td class="printHeading"><b>Amount: </b></td>
<td id="totalAmount1" class="printHeading">535</td>
</tr>
<tr>
<td class="printHeading"><b>Assessories: </b></td>
<td id="assessories1" class="printHeading">dfgdg</td>
</tr>
</table>
<hr/>
<div>T & C : NO Responsibility of data lost during service all Subject To Gwalior jurisdiction </div>
</center>
<!-- <div>Exe Name</div> -->
<div>
<h5 class="pull-right">Customer's Signature</h5>
</div>
</div>
This is my java script function
function printdiv(printpage)
{
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>";
var newstr = document.all.item(printpage).innerHTML;
var oldstr = document.body.innerHTML;
document.body.innerHTML = headstr+newstr+footstr;
window.print();
document.body.innerHTML = oldstr;
return false;
}
我认为这个问题可能有多种原因。 一方面,打印机驱动程序可能存在问题。可能页面在驱动程序中设置为特定高度,并且您的内容只是在页面上居中,也许您将边距设置为 3 厘米左右,这在 A4 纸上有意义,但在收据上则不然。
此外,您的 CSS 文件看起来有点短。我建议 always 放入类似
的内容*{
padding: 0px;
margin: 0px;
}
在 CSS 文件的前面,然后手动设置所有边距,以避免浏览器和打印机驱动程序可能会出现一些奇怪的事情...
您好,请使用以下链接代码: [https://plnkr.co/edit/sQiJfyaZYbFtChXWAjRn?p=preview][1]
或仅更改此:
@media print {
@page {
size: 10mm 20mm;
}
}
我用谷歌搜索了一下,看起来浏览器的打印页脚是问题所在。
也许这有帮助: https://www.odoo.com/forum/help-1/question/page-size-when-printing-pos-receipts-5443
它现在正在工作,在预览时,您会得到默认的边距,然后我们必须不留边距,之后就可以正常工作了