1

I have a form application in c# that reads HTML Invoice from web I want it to be textual output to print with POS printers.

<table border="1">
  <tr>
     <td>Hello</td>
     <td>World</td>
  </tr>
  <tr>
     <td>foo</td>
     <td>bar</td>
  </tr>
</table>

I am looking for something that can take the above table and create something like the following.

 ------------------------------
 | Hello     | World          |
 ------------------------------
 | foo       | bar            |
 ------------------------------
chriz
  • 1,339
  • 2
  • 16
  • 32
Sahil Ali
  • 113
  • 2
  • 11
  • 1
    [this](http://stackoverflow.com/questions/3934508/printing-a-formatted-html-page-in-c-sharp) should be helpful! – Anirudha Mar 18 '14 at 05:48
  • 2
    if I were you, I'd parse up the html, and have each html tag represent what you want to accomplish. So whenever you encounter a you make a series of dashes in a for loop. Go to next line, when you encounter a write your values delimited by a number of spaces and a "|", and so forth. Just find the patterns and you'd be set. – sksallaj Mar 18 '14 at 05:58
  • @Anirudha All this i'm doing due to lac of graphic print support in POS printers and if i'll use myWebBrowser.Print(); or direct print from browser... then result will be same – Sahil Ali Mar 18 '14 at 06:26
  • @sksallaj It's good but i stuck in how to determine spaces between two words – Sahil Ali Mar 18 '14 at 06:28
  • post some code so i can see where you're stuck – sksallaj Mar 18 '14 at 14:04

2 Answers2

0

let me give a try with jquery..

var innerHtml = $('#table').html();
innerHtml  = innerHtml.replaceAll('<table border="1">','');
innerHtml  = innerHtml.replaceAll('</table>','------------------------------');
innerHtml  = innerHtml.replaceAll('<tr>','------------------------------');
innerHtml  = innerHtml.replaceAll('<td>','   |  ');
innerHtml  = innerHtml.replaceAll('</td>','  |  ');
innerHtml  = innerHtml.replaceAll('</tr>','<br />');

and u can use this innerHtml to display ur table.. this answer is jst a try.. if its totaly wrong jst doenvote i ll remove it.. or if it k for u i can help u with fiddle

chriz
  • 1,339
  • 2
  • 16
  • 32
0

The jQuery code above in C#:

string innerHtml = getHTMLInvoiceFromWeb();
innerHtml  = innerHtml.Replace("<table border=\"1\">", "");
innerHtml  = innerHtml.Replace("</table>", "------------------------------");
innerHtml  = innerHtml.Replace("<tr>", "------------------------------");
//Use tabs instead of a fixed number of whitespace
innerHtml  = innerHtml.Replace("<td>", "|\t\t");
innerHtml  = innerHtml.Replace("</td>", "\t\t|\t\t");
innerHtml  = innerHtml.Replace("</tr>", "\n");

Finally, I haven't tried the code above, I just re-wrote chriz's jQuery code. I'd take another look at this when I get near my PC.