title: ESC commands to print barcode to a thermal printer?
body: <p>When you purchase a thermal receipt printer, you also get a manual that tells you which byte sequence should be used to do what (cutting, finishing job, setting fonts etc). However I do not have an understanding of Java that is sufficient for me to be able to use the ESC/POS commands.</p>
  
  <p>I have a Citizen CT S2000 thermal receipt printer. I have already managed to use the byte sequences for cutting and line feeding and manipulating what fonts the thermal printer is supposed to have. However I can not figure out how to use the ESC commands for generating and printing barcode.</p>
  
  <p>The manual on how to do this is <a href="http://www.citizen-systems.com/sites/default/files/CommandReference015E_120607_4.pdf#page=26&amp;zoom=auto,57,791" rel="nofollow noreferrer">here</a> on page 144. Here a sample code is provided in BASIC.</p>
  
  <pre><code>LPRINT CHR$(&amp;H1D);"k"; CHR$(73); CHR$(10);
  LPRINT "{BNo.{C"; CHR$(12); CHR$(34); CHR$(56);
  LPRINT CHR$(&amp;HA);
  END
  </code></pre>
  
  <p>Here is my attempt to print the barcode.</p>
  
  <pre><code>public static void barcode() throws Exception{
      byte[] b = {0x7b, 0x43, 0x12, 0x34}; 
      //This is the commands as I interpreted the to print out 12 and 34
  
      DocPrintJob job = PrintServiceLookup.lookupDefaultPrintService().createPrintJob();
  
      DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; 
      /*This is how I send byte sequences. 
      if you got something better then don't hesitate yelling at me :D : ). */
  
      Doc doc = new SimpleDoc(b, flavor, null);
  
      job.print(doc, null);                   
  }
  </code></pre>
  
  <p>Yet this does not yield anything at all and the printer doesn't do anything at all.</p>
  
  <p>I really can't find any examples of how to do it.</p>
  
  <p>Any answers/comments would be appreciated.</p>