Javascript 在80毫米宽的纸张上打印div
我投资了一台epson TM-T20II打印机,有80毫米宽的纸张 我有一个脚本,使我打印一个特定的隐藏div与一些文本,但问题是,文本打印约20毫米。两边都有边距,底部的空白纸是文本的两倍 我如何设置这个 我的代码如下所示:Javascript 在80毫米宽的纸张上打印div,javascript,php,printing,Javascript,Php,Printing,我投资了一台epson TM-T20II打印机,有80毫米宽的纸张 我有一个脚本,使我打印一个特定的隐藏div与一些文本,但问题是,文本打印约20毫米。两边都有边距,底部的空白纸是文本的两倍 我如何设置这个 我的代码如下所示: <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> <script ty
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script>
<script type="text/javascript">
function PrintElem(elem)
{
Popup($(elem).html());
}
function Popup(data)
{
var mywindow = window.open('', 'my div', 'height=50mm,width=80mm');
mywindow.document.write('<html><head><title>Handskemager Dans</title>');
/*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10
mywindow.print();
mywindow.close();
popupWindow.hide ();
return true;
}
</script>
函数PrintElem(elem)
{
弹出($(elem.html());
}
功能弹出窗口(数据)
{
var mywindow=window.open(“”,“我的div”,“高度=50mm,宽度=80mm”);
mywindow.document.write('Handskemager-Dans');
/*可选样式表*///mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(数据);
mywindow.document.write(“”);
mywindow.document.close();//对于IE>=10是必需的
mywindow.focus();//IE>=10所必需的
mywindow.print();
mywindow.close();
popupWindow.hide();
返回true;
}
而div只是:
<div id="mydiv" style="width:80mm;display:none;">
</div>
希望您能帮忙,我在打印机设置中找不到任何东西。我找到了答案
我只是用Chrome而不是Firefox,将纸张大小设置为“纸卷80毫米”,然后将边距设置为“最小”,然后一切都变得完美。你是否尝试过
*{padding:0;margin:0}
关闭浏览器默认边距和填充?我刚刚尝试过,但还是一样,还有其他建议吗?或者有没有其他方法可以打印特定文本,然后更改正在打印的纸张的大小?如果只打印简单的Hello
,而不打印任何HTML,它是否从左上角开始,没有任何页边距?