简体   繁体   English

JavaScript 打印用POS打印机纸张尺寸

[英]JavaScript print with POS printer paper size

I am trying to print specific div in POS printer.我正在尝试在 POS 打印机中打印特定的 div。 My printer name is Optimuz .我的打印机名称是Optimuz I also tried with我也试过

<div id="printAreaInvoice" style="visibility: hidden;font-size:8px;width:200px;"></div>
                        
<input type='button' id='printInvoice' value='Print'>

 $(document).on('click','#printInvoice',function () {
            printJS({
                maxWidth: 440, // the width of your paper
                printable: 'printAreaInvoice', // the id
                type: 'html',
                css: 'print.css' // your css
            });
        });

I loaded print content after page loaded.我在页面加载后加载了打印内容。 $('#printAreaInvoice').html(response.printData); $('#printAreaInvoice').html(response.printData);

contents loads on div like内容加载到 div 上

echo '<table class="tblData" style="width:100%;font-size:8px;">';
echo '<tr>';
echo '<td style="font-size:8px;">'.$item_name.' ---- '.$per_item_price.' </td>';

echo '</tr>';
echo '</table>';

But it takes full width.但它需要全宽。 Still I did not connect printer because of availability .由于可用性,我仍然没有连接打印机。 How can I fix that.我该如何解决。 Is it possible on that printer.那台打印机上可以吗。 Thanks in advance提前致谢

Last time I tried to use this library to print to POS printer.上次我尝试使用这个库打印到 POS 打印机。 You can check the library here PrintJS Library您可以在此处查看库PrintJS Library

When you use this library you can do something like this当你使用这个库时,你可以做这样的事情

<div id="print">
    <h1>My Heading</h1>
    <p>My Paragraph</p>
</div>

And to print this one you can use something JS like this要打印这个,你可以使用类似这样的 JS

printJS({ 
          maxWidth: 375, // the width of your paper
          printable: 'print', // the id
          type: 'html',
          css: 'print.css' // your css
});

In your print.css you will have something like this在你的 print.css 你会有这样的东西

@media print {
  #print h1 {
    font-size: 18pt;
  }
  #print p {
    font-size: 12pt;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM