0

I am unable to find any post which has answer to my issue.

I have html file which has a table, need to convert this to a text file without losing the format USING php script, as it has to be printed as is on a dotmatrix printer.

OR if there is any other way of doing this, pl suggest !

The table is a Invoice format, pl see below:

<table width='100' height='300' border='0' cellspacing='0' cellpadding='1'>  <tr>    <td><img src='spacer.jpg' width='100' height='1'></td>    <td><table width='840' border='1' cellspacing='2' cellpadding='0'><tr><td width='660' colspan='2' valign='top'><br><br><br><br><br><br><br><br><br>Customer Name: 3M India Ltd<br>
    Address:Plat 48-51 Electronic City<br><br></td><td width='180' valign='top'><br><br><br><br><br><br><br><br><br>
Inv No: 78788<br><br>Date:&nbsp;&nbsp;&nbsp;20/04/2012&nbsp;12:28:18<br><br> 
</td>  </tr>  <tr>    <td width='292' valign='top'>DC Nos: 500,&nbsp;    <br><br></td><td valign='top'> Your Order No.: 322<br>
       C.E.Reg No.: <br>
       Vehicle No.: KA-01-N-2345<br><td valign='top'> Party:<br>
TIN: 29400127541<br>
CST: 29400127541<br></td>  </tr>  <tr>    <td colspan='2'>Sl No. &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Description &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tariff Code &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rate &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Qty </td>    <td>Amount</td>  </tr>  <tr>    <td colspan='3'>     <table width='840' height='160' border='0' cellspacing='1' cellpadding='0'>     <tr valign='top'>       <td width='87'>1</td>       <td width='247'>Argon</td>      <td width='165'>AR1223</td>     <td width='92'>120</td>     <td width='67'>1&nbsp;Nos</td>      <td width='182'>120.00</td>     </tr>       </table>    </td>  </tr>  <tr> <td colspan='2' valign='top'><div align='right'><br>VAT: &nbsp;5.00 %<br>Demurrage: <br>   Freight:  <br><br>    </div>Rupees Four Hundred & Fourty One    Only.</td><td valign='top'><br> 21.00<br> 0.00<br> 300.00<br><br> </td>  </tr>  <tr>    <td colspan='2' valign='top'><div align='right'>Total:<br><br>Rounded Off</div></td>    <td valign='top'>441.00<br><br>441.00<br><br></td>  </tr></table>    </td>  </tr></table>
user1114409
  • 565
  • 3
  • 13
  • 26
  • Do you have the data backing the table, or are you needing to use an actual HTML file as the input? – jprofitt Apr 20 '12 at 12:18
  • This would not be a simple task to parse because not every char is the same width, you should output as you expect to use it. Im pretty sure you can print a table and format it with a print stylesheet with no parsing involved – Lawrence Cherone Apr 20 '12 at 12:20
  • 3
    If the HTML is well formed, this is (relatively) simple, you can just use a [DOM parser](http://php.net/manual/en/book.dom.php) to convert the data to an array, calculate the amount of white space padding that is needed for each column and output. If the HTML is *not* well formed you're in for a lot of fun. Where does the HTML come from? Did you generate it or somebody else? – DaveRandom Apr 20 '12 at 12:22
  • @LawrenceCherone If it's to be printed on a dotmatrix, chances are the output font would be monospaced. Although that does add a layer of complexity I hadn't thought about - if it isn't monospaced this is near enough impossible... – DaveRandom Apr 20 '12 at 12:24
  • The table is complex because it is a Invoice that has to be printed, I have converted a output php file in htm format. But not sure what is the best way to send this to dotmatrix printer - ascii. Will PDF solve this ? – user1114409 Apr 20 '12 at 12:40
  • Buy a new printer. They're not exactly expensive. :) – GordonM Apr 20 '12 at 14:09
  • The issue here is not buying a new printer, but the existing stationery worth lakhs, and at what speed it prints, it should be economical because we need 1+2 carbon copies, which can be printed only using dotmatrix. – user1114409 Apr 23 '12 at 12:47

1 Answers1

0

Could you not open the HTML file in something like Microsoft Word and then send it to print?

You could also convert the HTML file to PDF, there's several free ones (Google "html to pdf conversion") as another option to see if it works.

Manoj Solanki
  • 96
  • 1
  • 6
  • Hi Manoj, even if it is converted to PDF it will not print as ASCII in dotmatrix right ?, it will print it as graphics, which will slow down the printing of invoices. – user1114409 Apr 23 '12 at 12:45
  • I think it will depend to be honest, you'd have to try it and see. However, a potential solution to your problem might be this free printing software: [jzebra](http://code.google.com/p/jzebra/) – Manoj Solanki Apr 24 '12 at 08:27