|
|
|
@ -7,6 +7,7 @@ import json
|
|
|
|
|
import logging
|
|
|
|
|
import os.path
|
|
|
|
|
import random
|
|
|
|
|
import shutil
|
|
|
|
|
import string
|
|
|
|
|
import subprocess
|
|
|
|
|
import tempfile
|
|
|
|
@ -166,7 +167,6 @@ class Bureau(object):
|
|
|
|
|
self.commands = {}
|
|
|
|
|
self.api = {}
|
|
|
|
|
|
|
|
|
|
modpath = os.path.dirname(__file__)
|
|
|
|
|
mypath = inspect.getfile(self.__class__)
|
|
|
|
|
self.mdir = os.path.dirname(mypath)
|
|
|
|
|
|
|
|
|
@ -175,6 +175,17 @@ class Bureau(object):
|
|
|
|
|
os.mkdir(basepath)
|
|
|
|
|
os.chdir(basepath)
|
|
|
|
|
|
|
|
|
|
# make sure fonts are copied
|
|
|
|
|
fontpath = os.path.join(basepath, "fonts")
|
|
|
|
|
fontsrc = os.path.join(self.mdir, "fonts")
|
|
|
|
|
if os.path.exists(fontsrc):
|
|
|
|
|
fontlist = glob.glob(os.path.join(fontsrc, "*.otf"))
|
|
|
|
|
fontlist += glob.glob(os.path.join(fontsrc, "*.ttf"))
|
|
|
|
|
for fontfile in fontlist:
|
|
|
|
|
fontbase = os.path.basename(fontfile)
|
|
|
|
|
if not os.path.exists(os.path.join(fontpath, fontbase)):
|
|
|
|
|
shutil.copy(fontfile, fontpath)
|
|
|
|
|
|
|
|
|
|
self.load_config()
|
|
|
|
|
|
|
|
|
|
# setup log file
|
|
|
|
@ -355,20 +366,7 @@ class Bureau(object):
|
|
|
|
|
pdfpath = tempfile.mkstemp(".pdf")[1]
|
|
|
|
|
self.log.debug("rendering to: " + pdfpath)
|
|
|
|
|
|
|
|
|
|
# manually add local fonts
|
|
|
|
|
fontconfig = FontConfiguration()
|
|
|
|
|
fontsdir = os.path.join(self.mdir, "fonts")
|
|
|
|
|
fontlist = []
|
|
|
|
|
for font in glob.glob(fontsdir + "/*.otf"):
|
|
|
|
|
fontlist.append(("local", "file://" + font))
|
|
|
|
|
self.log.debug("adding font " + font)
|
|
|
|
|
for font in glob.glob(fontsdir + "/*.ttf"):
|
|
|
|
|
fontlist.append(("local", "file://" + font))
|
|
|
|
|
self.log.debug("adding font " + font)
|
|
|
|
|
fdict = { "src": fontlist }
|
|
|
|
|
fontconfig.add_font_face(fdict,
|
|
|
|
|
weasyprint.default_url_fetcher)
|
|
|
|
|
weasyprint.HTML(string=templ.render_unicode(**kwargs)).write_pdf(pdfpath, font_config=fontconfig)
|
|
|
|
|
weasyprint.HTML(string=templ.render_unicode(**kwargs)).write_pdf(pdfpath)
|
|
|
|
|
subprocess.call("lpr -o sides=two-sided-long-edge -o InputSlot=Upper " + pdfpath, shell=True)
|
|
|
|
|
|
|
|
|
|
# TODO: make this asynchronous
|
|
|
|
|