有没有办法让打印机将其视为文本文件?或者有没有办法将html页面转换为文本文件而不会丢失位置样式(间距,边距等)? 或者可能有我可以使用的替代方法? 需要注意的一点是,我不能使用基于文本的浏览器来执行此操作,因为客户将使用它。
发票是一个html表,左上角有小徽标,标题和描述为thead,简单表格单元格为边框为tbody。
我使用Epson LX300 + II打印机。
答案 0 :(得分:1)
<?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>
答案 1 :(得分:0)
我们曾经使用Java Applet执行此操作,该Java Applet可以在浏览器和Java安全性的适当权限之后写入LPT端口。
然而,所有浏览器都已逐步取消对此的支持。我们现在通过使用旧版本的浏览器来运行它。
我们正在探索的一种方法是在本地PC上的端口上运行java服务并从浏览器窗口调用此服务。
答案 2 :(得分:0)
解决此问题的一个选项是下载TCPDF库https://tcpdf.org/docs/srcdoc/并将报告传递给pdf,但您必须下载一些dotmatrix类型字体并使用链接http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf,将字体转换为格式TCPDF使用。
答案 3 :(得分:0)
我几乎有这样的要求,我没有一个完美的解决方案,所以我使用了替代解决方案,
在此解决方案中,无法获得所有解决方案。
答案 4 :(得分:-1)
<!DOCTYPE html>
<html lang="es">
<head>
<title>print-boleta</title>
<meta charset="UTF-8">
<style type="text/css">
@media print {
header {
background: none;
color: #000;
}
aside#sidebar, header[role="banner"], footer, #comments, #respond {
display: none;
}
#container #content #main {
width: 100%;
margin: 0px;
padding: 0px;
}
* {
color: #000;
background-color: #fff;
@include box-shadow(none);
@include text-shadow(none);
}
@page {
size: A4 portrait;
margin-top: 4cm;
margin-bottom: 1cm;
margin-right: 1cm;
margin-left: 1cm;
font-family: sans-serif, Verdana, Geneva !important;
font-size: 10px !important;
}
}
@media screen {
#container {
background: tomato;
font-size: 12px;
font-family: sans-serif;
}
}
</style>
</head>
<body>
<input type="hidden" id="imprimir" name="imprimir" value="S"/>
<div id="container">
<?php
require_once '../conf/conexion.php';
require_once '../libs/funciones_gen.php';
require_once '../libs/letras.php';
$meses = array("", "ENERO", "FEBRERO", "MARZO", "ABRIL", "MAYO", "JUNIO", "JULIO", "AGOSTO", "SETIEMBRE", "OCTUBRE", "NOVIEMBRE", "DICIEMBRE");
$query = "SELECT
ventas.id_venta,
ventas.id_cliente,
ventas.id_comprobante,
ventas.id_condicion,
ventas.num_comprobante,
ventas.fecha_venta,
ventas.total_venta,
comprobantes.comprobante,
condiciones.condicion,
clientes.cliente,
clientes.direccion,
clientes.dni_ruc,
clientes.telefono
FROM
ventas
INNER JOIN comprobantes ON ventas.id_comprobante = comprobantes.id_comprobante
INNER JOIN condiciones ON ventas.id_condicion = condiciones.id_condicion
INNER JOIN clientes ON ventas.id_cliente = clientes.id_cliente
WHERE ventas.id_venta = " . $_GET['id'] . "";
$res = mysql_query($query); //echo $query;
$reg = mysql_fetch_array($res);
$dia = substr($reg['fecha_venta'], 8, 2);
$mes = substr($reg['fecha_venta'], 5, 2);
$nmes = $mes * 1;
$anio = substr($reg['fecha_venta'], 0, 4);
?>
<table width="870" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="10%" style="height: 18px;"> </td>
<td width="70%" colspan="2">
<?php echo sub_cad(trim($reg['cliente'], "ยบ"), 32); ?>
</td>
<td width="20%" colspan="2" align="right">
</td>
</tr>
<tr>
<td width="10%" style="height: 18px;"> </td>
<td width="70%" colspan="2">
<?php echo sub_cad(trim($reg['direccion'], "ยบ"), 32) ?>
</td>
<td width="20%" colspan="2" align="center">
</td>
</tr>
<tr>
<td width="10%" style="height: 18px;"> </td>
<td width="45%" colspan="2">
<?php echo trim($reg['dni_ruc']) ?>
</td>
<td width="45%" colspan="2" align="right">
<?php
echo $dia .
" " .
" " .
" " .
$mes .
" " .
" " .
$anio
?>
</td>
</tr>
<tr>
<td colspan="5" style="height: 18px"> </td>
</tr>
</table>
<table width="870" cellpadding="0" cellspacing="0" border="0">
<?php
$sql = "SELECT
prod_ventas.id_venta,
prod_ventas.cantidad,
prod_ventas.precio_unitario,
prod_ventas.descuento,
prod_ventas.importe,
productos.id_producto,
productos.codigo,
productos.producto
FROM
prod_ventas
INNER JOIN productos ON prod_ventas.id_producto = productos.id_producto
WHERE prod_ventas.id_venta = " . $_GET['id'];
$result = mysql_query($sql); //echo $query;
$numReg = mysql_num_rows($result);
if ($numReg == 27) {
$valign = "top";
} else {
$valign = "bottom";
}
$item = 1;
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td width="70" height="20px" align="center">
<?php echo $row['cantidad'] ?>
</td>
<td width="100">
<?php echo $row['codigo'] ?>
</td>
<td width="205">
<?php echo sub_cad(trim($row['producto'], "ยบ"), 28) ?>
</td>
<td width="80" align="right">
<?php echo $row['precio_unitario'] ?>
</td>
<td width="100" align="right">
<?php echo number_format(($row['cantidad'] * $row['precio_unitario']), 2); ?>
</td>
</tr>
<?php
}
for ($i = 0; $i < 7 - $numReg; $i++) {
?>
<tr>
<td width="70" height="20px" align="center"> </td>
<td width="100"> </td>
<td width="205"> </td>
<td width="80" align="right"> </td>
<td width="100" align="right"> </td>
</tr>
<?php
}
?>
</table>
<table width="870" border="0" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
<td style="height:22px;"> </td>
</tr>
<tr>
<td style="height:30px;"> </td>
<td align="right">
<?php echo number_format($reg['total_venta'], 2); ?>
</td>
</tr>
</table>
</div>
<script src="../js/jquery-1.11.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var printing = $("#imprimir").val();
if (printing == 'S') {
window.print();
} else {
window.close();
}
});
</script>
</body>
</html>
&#13;
到目前为止我遇到了同样的问题这个代码我没有得到很好的结果但是eta的东西,我留下以防万一我的情况有任何改进是EPSON LX-350打印机