1

我有一个 php 网站,它以 html 表格的形式生成发票,我需要将这些 html 表格打印到点阵打印机。我曾尝试使用浏览器打印选项直接打印网页,但似乎打印机将其视为图像,因为它像 ascii 文本文件一样逐点打印字符而不是完整字符,这会导致模糊人物。

有没有办法让打印机把它当作文本文件?或者有什么方法可以在不丢失位置样式(间距、边距等)的情况下将 html 页面转换为文本文件?或者也许我可以使用另一种方法?需要注意的一件事是我不能使用基于文本的浏览器来执行此操作,因为它将被客户端使用。

发票是一个 html 表格,左上角有小 logo,标题和描述为 thead,简单的表格单元格为 tbody。

我使用爱普生 LX300+II 打印机。

4

5 回答 5

2
<?php
 // Download printer driver for dot matrix printer ex. 1979 Dot Matrix      Regular or Consola

?>
<html>
<head>
<title>PHP to Dot Matrix Printer</title>

<style>
@font-face { font-family: kitfont; src: url('1979 Dot Matrix Regular.TTF'); } 

.customFont { /*  <div class="customFont" /> */
font-style: kitfont;
font-size:10;
}
#mainDiv {
height: 324px; /* height of receipt 4.5 inches*/
width: 618px;  /* weight of receipt 8.6 inches*/
position:relative; /* positioned relative to its normal position */
}
#cqm { /*  <img id="cqm" /> */
top: 10px; /* top is distance from top (x axis)*/
left: 105px; /* left is distance from left (y axis)*/
position:absolute; /* position absolute based on "top" and "left"    parameters x and y  */
}

#or_mto { 
position: absolute;
left: 0px;
top: 0px;
z-index: -1; /*image */
}

    #arpno {
top: 80px;
left: 10px;
position:absolute;
}
#payee {
top: 80px;
left: 200px;
position:absolute;
}
#credit {
top: 80px;
right: 30px; /*   distance from right */
position:absolute;
}
#paydate {
top: 57px;
right: 120px;
position:absolute;
}
 </style>

</head>
<body>
<?php
//sample data

$arpno   = 1234567;
$payee   = "Juan dela Cruz";
$credit  = 10000;
$paydate = "Dec. 6, 2015" ;


?>
<div id="mainDiv"> <!--  invisible space -->
<div id="cqm" class="customFont">ABC TRADING</div>
<div id="arpno" class="customFont"><?php echo $arpno; ?></div>
<div id="payee" class="customFont"><?php echo $payee; ?></div>
<div id="credit" class="customFont"><?php echo $credit; ?></div>
<div id="paydate" class="customFont"><?php echo $paydate; ?></div>
<img id="or_mto" src="or_mto.jpg" /> <!---- sample for logo  ---->
</div>

</body>
</html>
于 2015-12-06T04:53:24.443 回答
1

对于希望直接从浏览器打印到打印机并假设您只需要打印文本的任何人,我在这篇文章how-to-print-page-in-plain-text-format-for-matrix-dot-printer中找到了答案

该应用程序的 Github 在这里

一个简单的教程可以在这里找到。

基本上,您在客户端机器上安装 QZ Tray,然后在您的 html 中添加它们提供的脚本。

使用 OKI 320 Turbo Dot Matrix Printer 在 Windows 10 中工作正常,但您必须将打印机的驱动程序更改为 Generic / Text Only。

然后在 javascript 中,您只需执行以下操作:

try {
    
    await qz.websocket.connect();
    console.log("connected")

    const printer = await qz.printers.find("OKI");
    console.log(`Printer ${printer} found !`);

    const config = qz.configs.create(printer);
    const data = [
        'Some Data \n',
        'More Data   and More Data  \n'
    ]

    qz.print(config, data);

} catch(e) { console.log(e) }

奇迹般有效!

于 2021-12-02T14:44:09.340 回答
0

我们曾经使用 Java Applet 来执行此操作,该 Applet 可以在浏览器和 Java 安全性获得适当权限后写入 LPT 端口。

但是,所有浏览器都已逐步取消对此的支持。我们现在正在使用旧版本的浏览器运行它。

我们正在探索的一种方法是在本地 PC 的端口上运行 java 服务并从浏览器窗口调用该服务的可能性。

于 2017-09-12T05:24:08.713 回答
0

我有几乎相同的要求,我没有得到完美的解决方案,所以我使用了替代解决方案,

  • 在“w3m”的帮助下将 html 转换为文本
  • 通过套接字通信将此文本发送到在客户端计算机上运行的 python 脚本
  • 通过python脚本(使用pyusb),我通过USB将此文本直接发送到打印机并打印。

在此解决方案中,无法打印所有解决方案。

于 2018-08-01T14:52:59.383 回答
0

解决此问题的一个选项是下载 TCPDF 库https://tcpdf.org/docs/srcdoc/并将报告传递给 pdf,但您必须下载一些点阵字体并使用链接http://www.xml -convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf,将字体转换为 TCPDF 使用的格式。

于 2018-04-28T23:07:53.567 回答