clean up article style. embed custom fonts. remove cruft from print_full mmethod

workspace
Brendan Howell 6 years ago
parent 44c85950cc
commit 084a9f0c3f

@ -314,34 +314,15 @@ class Bureau(object):
def print_full(self, template, **kwargs): def print_full(self, template, **kwargs):
"""print a full page (A4) document """ """print a full page (A4) document """
# TODO: look up the printer LPR name / allow multiple printers/non-default # TODO: look up the printer LPR name / allow multiple printers/non-default
# lpname = kwargs.get("printer", "default")
#htmlfile, htmlpath = tempfile.mkstemp(".html")
#htmlfile = os.fdopen(htmlfile, "w")
# run template with kwargs # run template with kwargs
templfile = os.path.join(self.mdir, template) templfile = os.path.join(self.mdir, template)
self.log.debug("printing with template: %s", templfile) self.log.debug("printing with template: %s", templfile)
templ = Template(filename=templfile, strict_undefined=True) templ = Template(filename=templfile, strict_undefined=True)
#htmlfile.write(templ.render_unicode(**kwargs))
#htmlfile.close()
#.encode('utf-8',
# 'replace'))
# texfile, texfilepath = tempfile.mkstemp(".tex")
# texfile.write(templ.render_unicode(
# **kwargs).encode('utf-8', 'replace'))
# texdir = os.path.dirname(texfilepath)
# subprocess.call("cd " + texdir + "; xelatex " + texfilepath)
# TODO: make paper size a config variable # TODO: make paper size a config variable
pdfpath = tempfile.mkstemp(".pdf")[1] pdfpath = tempfile.mkstemp(".pdf")[1]
self.log.debug("rendering to: " + pdfpath) self.log.debug("rendering to: " + pdfpath)
weasyprint.HTML(string=templ.render_unicode(**kwargs)).write_pdf(pdfpath) weasyprint.HTML(string=templ.render_unicode(**kwargs)).write_pdf(pdfpath)
#subprocess.call(self.html2pdf + htmlpath + " " + pdfpath +
# " A4 1920px", shell=True)
subprocess.call("lpr -o sides=two-sided-long-edge -o InputSlot=Upper " + pdfpath, shell=True) subprocess.call("lpr -o sides=two-sided-long-edge -o InputSlot=Upper " + pdfpath, shell=True)
# TODO: make this asynchronous # TODO: make this asynchronous

@ -3,8 +3,14 @@
<title>${title}</title> <title>${title}</title>
<meta charset="utf-8"> <meta charset="utf-8">
<style type="text/css"> <style type="text/css">
@media print {
@page {
size: A4;
margin: 1cm;
}
}
body { body {
font-family: Junicode; font-family: "CMU Serif";
font-size: 10pt; font-size: 10pt;
line-height: 1; line-height: 1;
counter-reset: sidenote-counter; counter-reset: sidenote-counter;

@ -9,6 +9,10 @@
margin: 1cm; margin: 1cm;
} }
} }
@font-face {
font-family: Fold;
src: url("fonts/Fold.otf") format("opentype");
}
html { html {
font-size: 100%; font-size: 100%;
} }

@ -172,7 +172,11 @@ class Publications(Bureau):
notetext = html.makeelement("div") notetext = html.makeelement("div")
notetext.text = str(notecount) + ". " + link.attrib["href"] notetext.text = str(notecount) + ". " + link.attrib["href"]
footnote.append(notetext) footnote.append(notetext)
footnote.append(lxml.html.fromstring(svg.encode())) #TODO: make this barcode inline thing a util method
encoded_svg = b64encode(bytes(svg, 'utf-8')).decode()
encoded_data = "data:image/svg+xml;charset=utf-8;base64," + encoded_svg
svg = '<img src="%s"/>' % encoded_data
footnote.append(svg)
html.append(footnote) html.append(footnote)
self.print_full("article.html", title=doc.title(), self.print_full("article.html", title=doc.title(),

Loading…
Cancel
Save