How to send raw string to a dotmatrix printer using python in ubuntu?
<p>I have a dot-matrix printer LX-300 connected to my computer through the network. How do I send a raw string with ESCP characters directly to my printer in Python?</p>

<p>The computer is connected to the printer through another computer. I need to send a raw string because LX-300 image printing result is blurry.</p>

<p>Ultimately, you will need and want to write your own wrapper/script to do this. And since you are using a distribution of Linux, this is relatively easy.</p>

<p>On a Linux OS, the simplest way to issue a print job is to open a <a href="http://docs.python.org/3/library/subprocess.html" rel="nofollow" title="subprocess">subprocess</a> to the <a href="http://www.computerhope.com/unix/ulpr.htm" rel="nofollow">lpr</a>. Generally, using <code>lpr</code> lets you access the printer without the need to be logged in as root (being a superuser), which is desirable considering the amount of damage that can be done while logged in as a "superuser".</p>

<p>Code like the following:</p>

<pre><code>import subprocess
lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE)
lpr.stdin.write(data_to_send_to_printer)
</code></pre>

<p>Should be a good jumping off point for you. Essentially, this code should allow you to accomplish what you need.</p>

<p><strong>Be careful though; depending on your privilege levels, a call to open a subprocess might need root level/Superuser permissions.</strong></p>

<p>Subprocesses generally <a href="http://stackoverflow.com/questions/22233454/will-a-python-subprocess-popen-call-inherit-root-privs-if-the-calling-script-i" title="inherit">inherit</a> the User IDs and access rights by the user that is running the command. For example, if the subprocess is created by a root user, then you will need root user/Superuser rights to access that subprocess.</p>

<p>For more information, check out the hyperlinks I've included in the post.</p>

<p>Good luck!</p>

python epson dot-matrix escpos