class priceList: class MultiCol(Environment): packages = [Package('multicol')] escape = False content_seperator = "\n" _latex_name = 'multicols' def __init__(self, pdfName='full'): self.geometry_options = ["margin=0.25in", "portrait"] self.document_options = "" self.font_size = 'normalsize' self.documentclass = "article" self.inputenc = "utf8" self.page_numbers = False self.data = None self.document = None self.pdfName = pdfName def productNameWrapped(self, prod): name = prod if len(name) > 18: if len(name) >= 16 * 2: name[32:] = u'\u2026' return name else: return name def makeDoc(self, craftBeerDict): self.document = Document(documentclass=self.documentclass, document_toptions=self.document_options, font_size=self.font_size, page_numbers=self.page_numbers, inputenc=self.inputenc, geometry_options=self.geometry_options, data=self.data) # Force enumitem package into document to change list seperation values self.document.packages.add(NoEscape('\usepackage{enumitem}')) self.document.packages.add(NoEscape('\usepackage[T1]{fontenc}')) self.document.packages.add(NoEscape('\usepackage{nimbussans}')) self.document.packages.add(NoEscape('\usepackage[table]{xcolor}')) self.document.packages.add(NoEscape('\usepackage{hanging}')) self.document._propagate_packages() self.document.append(NoEscape('\setlist{nosep}')) self.document.append(NoEscape('\setlength{\columnseprule}{0.5pt}')) self.document.append(NoEscape('\setlength{\columnsep}{1cm}')) self.document.append( NoEscape('\\renewcommand{\\familydefault}{\sfdefault}')) self.document.append(NoEscape('\sffamily')) self.document.append(NoEscape('\definecolor{lightgray}{gray}{0.9}')) self.document.append(NoEscape('\\rowcolors{1}{}{lightgray}')) with self.document.create(self.MultiCol(arguments='3')): self.document.append( Section(NoEscape('\\fontfamily{fvm}\selectfont ' + listName), numbering=False)) for brewery in craftBeerDict.keys(): with self.document.create(Subsection(brewery, numbering=False)): with self.document.create( Tabular( NoEscape( '>{\\raggedright}p{16ex\hangindent=3ex} c r' ))) as brewTable: for beer in craftBeerDict[brewery]: brewTable.add_row([ self.productNameWrapped(beer['product']), beer['size'] + ' x ' + beer['pack'], beer['price'] ]) print "Making price list..." self.document.generate_pdf(self.pdfName, clean=True, clean_tex=False, silent=True) #print os.getcwd()+'/'+self.pdfName+".pdf" subprocess.call( ["xdg-open", os.getcwd() + '/' + self.pdfName + ".pdf"])