【发布时间】:2015-08-04 13:20:19
【问题描述】:
我投资了一台 epson TM-T20II 打印机,纸张宽 80 毫米。
我有一个脚本,可以让我打印带有一些文本的特定隐藏 div,但问题是,打印的文本大约有 20 毫米。两边的边距和底部的空白纸是文本的两倍。
我该如何设置?
我的代码如下:
<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>
而 div 就是:
<div id="mydiv" style="width:80mm;display:none;">
</div>
希望您能提供帮助,我在打印机设置中找不到任何内容。
【问题讨论】:
-
你试过
* {padding: 0; margin: 0}关闭浏览器默认边距和内边距吗? -
我刚试了下还是一样,还有什么建议吗?
-
或者是否有另一种方法来打印特定文本,然后更改正在打印的纸张的大小
-
如果你只打印简单的
Hello没有任何HTML,它是从左上角开始没有任何边距吗?
标签: javascript php printing