From 83fc86a1c185ae71072089d60bb226b98bf63d39 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Fri, 18 Mar 2016 17:42:36 +0100 Subject: [PATCH] tidy up print methods and switch to slimerjs for rendering pdf --- screenless/bureau/bureau.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py index 19d0c45..8162811 100644 --- a/screenless/bureau/bureau.py +++ b/screenless/bureau/bureau.py @@ -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,7 +125,10 @@ class Bureau(object): if len(resp) == 0: return None elif resp[0] == "0": - return json.loads(resp[1:]) + if len(resp) == 1: + return None + else: + return json.loads(resp[1:]) else: # TODO: this may need some better error handling return resp @@ -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)