Php – Print HTML table to dot matrix printer

dot-matrixhtmlPHPprinting

I have a php website which generate invoice in the form of html tables, I need to print these html tables to dot-matrix printer. I have tried to print webpage directly with browser print option, but it seems the printer treat it as image because it prints characters dot-by-dot instead of complete characters in a single pass like it would an ascii text file, which result in blurred characters.

Is there any way to make the printer treat it as text file? Or is there any way to convert html page to text file without losing the position styling(spacing, margins, etc)?
Or maybe there's an alternative approach I could use?
One thing to note is I can't use text-based browser to do this as it will be used by clients.

The invoice is a html table with small logo at the top-left, title, and description as thead, and simple table cell with borders as tbody.

I use Epson LX300+II printer.

Best Answer

<?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>