Skip to content

Instantly share code, notes, and snippets.

@bilke
Created January 24, 2011 20:52
Show Gist options
  • Save bilke/793922 to your computer and use it in GitHub Desktop.
Save bilke/793922 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os, glob, errno, sys, time, re
if len(sys.argv) > 1:
fin_filename = sys.argv[1]
else:
fin_filename = 'druck_orig.txt'
fin = open(fin_filename, 'r')
fout = open('druck_bearbeitet.txt', 'w')
fin_string = fin.read()
# Suchstring für Dokument
for doc_match in re.finditer(r"\x0d\x1b\x45\x1b", fin_string):
pass
if doc_match:
matchstart = doc_match.start()
print matchstart
f_temp = open('druck_temp.txt', 'w')
f_temp.write(fin_string[matchstart:])
f_temp.close()
f_temp = open('druck_temp.txt', 'r')
fout_string = ''
i = 0
for line in f_temp:
if i < 1:
print str(len(line)) + " " + repr(line)
match = re.search("(.*)([\x1B]\(s16.66H)(.*)", line)
if match:
match1 = repr(match.group(1))
match2 = match.group(2)
match3 = repr(match.group(3))
print "Match 1:" + match1
print "Match 2:" + match2
print "Match 3:" + match3
line = chr(13) + match2 # line feed
line = re.sub("16.66", "12", line) # Schriftgröße
append_string = chr(13) + chr(13) + chr(10)
line += append_string
print repr(line)
fout_string += line
i += 1
fout.write(fout_string)
fout.close()
fin.close()
f_temp.close()
if os.name == 'nt':
os.system ("copy druck_bearbeitet.txt LPT1")
#os.remove('druck_bearbeitet.txt')
os.remove('druck_temp.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment