【问题标题】:Printing a div on 80 mm wide paper在 80 毫米宽的纸上打印 div
【发布时间】: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


【解决方案1】:

我找到了答案。

我只是使用 Chrome 而不是 Firefox,并将纸张尺寸设置为“Paper Roll 80 mm”,然后将边距设置为“Minimum”,然后一切都很完美。

【讨论】:

    猜你喜欢
    • 2016-11-05
    • 2020-08-19
    • 1970-01-01
    • 2017-05-19
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 2016-05-29
    相关资源
    最近更新 更多