tidy up print methods and switch to slimerjs for rendering pdf

workspace
Brendan Howell 9 years ago
parent 986cbaec83
commit 83fc86a1c1

@ -6,6 +6,7 @@ import json
import os.path
import subprocess
import tempfile
import textwrap
import threading
import time
@ -67,11 +68,10 @@ class Bureau(object):
self.api = {}
modpath = os.path.dirname(__file__)
phantomjs = os.path.join(modpath, "..", "lib", "phantomjs", "bin",
"phantomjs")
slimerjs = os.path.join(modpath, "..", "lib", "slimerjs", "slimerjs")
renderer = os.path.join(modpath, "..", "lib", "rasterize.js")
self.phantomjs = os.path.abspath(phantomjs)
self.html2pdf = self.phantomjs + " " + os.path.abspath(renderer) + " "
self.slimerjs = os.path.abspath(slimerjs)
self.html2pdf = self.slimerjs + " " + os.path.abspath(renderer) + " "
mypath = inspect.getfile(self.__class__)
self.mdir = os.path.dirname(mypath)
@ -125,6 +125,9 @@ class Bureau(object):
if len(resp) == 0:
return None
elif resp[0] == "0":
if len(resp) == 1:
return None
else:
return json.loads(resp[1:])
else:
# TODO: this may need some better error handling
@ -213,15 +216,16 @@ class Bureau(object):
print("rendering with: ", self.html2pdf + htmlpath + " " + pdfpath)
subprocess.call(self.html2pdf + htmlpath + " " + pdfpath +
" A4 1920px", shell=True)
#subprocess.call("lpr " + pdfpath, shell=True)
subprocess.call("lpr " + pdfpath, shell=True)
# TODO: make this asynchronous
def print_small(self, text, printer="/dev/usb/lp0"):
"""
print on Thermal Line printer.
"""
# TODO: look this up in config
# TODO: look up device and width in config
lp = open(printer, "w")
text = textwrap.fill(text, width=32)
text += "\r\n" * 5
# text += ".d0"
lp.write(text)

Loading…
Cancel
Save