def _showDoc(fn,story): pageTemplate = PageTemplate('normal', [Frame(72, 440, 170, 284, id='F1'), Frame(326, 440, 170, 284, id='F2'), Frame(72, 72, 170, 284, id='F3'), Frame(326, 72, 170, 284, id='F4'), ], myMainPageFrame) doc = BaseDocTemplate(outputfile(fn), pageTemplates = pageTemplate, showBoundary = 1, ) doc.multiBuild(story)
def multiBuild(self,flowables,onFirstPage=_doNothing, onLaterPages=_doNothing): self._calc() #in case we changed margins sizes etc frameFirst = Frame(2*cm, 2*cm, 17*cm, 23*cm, id='F1') frameLater = Frame(2.5*cm, 2*cm, 16*cm, 24.5*cm, id='F2') self.addPageTemplates([ PageTemplate (id='First',frames=frameFirst, onPage=onFirstPage, pagesize=self.pagesize), PageTemplate(id='Later',frames=frameLater, onPage=onLaterPages, pagesize=self.pagesize) ]) BaseDocTemplate.multiBuild(self,flowables)
def _showDoc(fn, story): pageTemplate = PageTemplate( "normal", [ Frame(72, 440, 170, 284, id="F1"), Frame(326, 440, 170, 284, id="F2"), Frame(72, 72, 170, 284, id="F3"), Frame(326, 72, 170, 284, id="F4"), ], myMainPageFrame, ) doc = BaseDocTemplate(outputfile(fn), pageTemplates=pageTemplate, showBoundary=1) doc.multiBuild(story)
def multiBuild(self, flowables, onFirstPage=_doNothing, onLaterPages=_doNothing): self._calc() #in case we changed margins sizes etc frameFirst = Frame(2 * cm, 2 * cm, 17 * cm, 23 * cm, id='F1') frameLater = Frame(2.5 * cm, 2 * cm, 16 * cm, 24.5 * cm, id='F2') self.addPageTemplates([ PageTemplate(id='First', frames=frameFirst, onPage=onFirstPage, pagesize=self.pagesize), PageTemplate(id='Later', frames=frameLater, onPage=onLaterPages, pagesize=self.pagesize) ]) BaseDocTemplate.multiBuild(self, flowables)
def make_invoice(fp, purchase, org, pgnum, tickets, **kw): """ make pdf invoice. Should be called with the same parameters as the render_template with the html template. """ doc = BaseDocTemplate(fp, pagesize=A4) styles = getSampleStyleSheet() args = dict(date=purchase.date[0], rcptaddr=[purchase.buyerName[0]], senderaddr=[org.name[0]], orgnum=org.orgnum[0], fskatt=org.fskatt[0], kind=purchase.kind[0], ocr=purchase.ocr[0], conditions='30 dagar netto', latefee=u'Efter förfallodatum debiteras ' u'dröjsmålsränta enligt räntelagen.', total=purchase.total[0], pgnum=pgnum, styles=styles) qrcode = { 'uqr': 1, 'tp': 1, 'nme': org.name[0], 'cid': org.orgnum[0], 'idt': time.strftime('%Y%m%d', time.localtime(purchase.date[0])), 'iref': purchase.ocr[0], 'due': str(purchase.total[0]), 'pt': 'PG', 'acc': pgnum[:-1] + '-' + pgnum[-1:] } if purchase.buyerAddress: args['rcptaddr'] += purchase.buyerAddress[0].split('\n') if org.address: args['senderaddr'] += org.address[0].split('\n') if org.phone: args['phone'] = org.phone[0] if org.email: args['email'] = org.email[0] if org.url: args['url'] = org.url[0] if org.seat: args['seat'] = org.seat[0] if org.vatnum: args['vatnum'] = org.vatnum[0] if purchase.buyerReference: args['buyerref'] = purchase.buyerReference[0] if purchase.buyerAnnotation: args['annotation'] = purchase.buyerAnnotation[0].split('\n') for (code, pct, value) in purchase.vat: qrcode[{'10': 'vh', '11': 'vm', '12': 'vl'}[code]] = str(value) try: args['expiryDate'] = purchase.expiryDate[0] qrcode['ddt'] = time.strftime('%Y%m%d', time.localtime(purchase.expiryDate[0])) except (AttributeError, IndexError): qrcode['ddt'] = time.strftime('%Y%m%d') args['qrcode'] = json.dumps(qrcode) tmpl = InvoiceTemplate(name='invoice', **args) tmpl2 = Invoice2Template(name='invoice2', **args) doc.addPageTemplates([tmpl, tmpl2]) elements = [NextPageTemplate('invoice'), NextPageTemplate('invoice2')] indentedsmallstyle = ParagraphStyle('Small', fontName='Helvetica', fontSize=8, leading=9, leftIndent=5 * mm) boldstyle = ParagraphStyle('Bold', fontName='Helvetica-Bold', fontSize=10, leading=12) boldrightstyle = ParagraphStyle('Bold', fontName='Helvetica-Bold', fontSize=10, leading=12, alignment=TA_RIGHT) mycellstyle = CellStyle('mycellstyle') mycellstyle.topPadding = mycellstyle.bottomPadding = 0 tabledata = [ Table( [[ Paragraph(_('Item'), boldstyle), Paragraph(_('Price'), boldrightstyle), Paragraph(_('Quantity'), boldrightstyle), Paragraph(_('Total'), boldrightstyle) ]], colWidths=[115 * mm, 20 * mm, 20 * mm, 25 * mm], style=TableStyle([ ('ALIGN', (1, 0), (-1, -1), 'RIGHT'), ('TOPPADDING', (0, 0), (-1, -1), 0), ('BOTTOMPADDING', (0, 0), (-1, -1), 0), #('BOX', (0,0), (-1, -1), 0.25, colors.black), ])) ] for item in purchase.items: celldata = [ Table( [[ item.name[0], formatters.money(item.price[0], True), item.quantity[0], formatters.money(item.total[0], True) ]], colWidths=[115 * mm, 20 * mm, 20 * mm, 25 * mm], style=TableStyle([ ('ALIGN', (1, 0), (-1, -1), 'RIGHT'), ('TOPPADDING', (0, 0), (-1, -1), 0), ('BOTTOMPADDING', (0, 0), (-1, -1), 0), #('BOX', (0,0), (-1, -1), 0.25, colors.black), #('ALIGN', (0,0), (-1, 0), 'LEFT') ]), ) ] if item.options: for opt, val in item.optionsWithValue: celldata.append( Paragraph('%s: <i>%s</i>' % (opt, val), indentedsmallstyle)) tabledata.append(celldata) # Sum and VAT tabledata.append([ Table( [[ '', Paragraph(_('Total'), boldrightstyle), Paragraph(formatters.money(purchase.total[0], True), boldrightstyle) ]], colWidths=[115 * mm, 40 * mm, 25 * mm], style=TableStyle([ ('ALIGN', (1, 0), (-1, -1), 'RIGHT'), ('TOPPADDING', (0, 0), (-1, -1), 0), ('BOTTOMPADDING', (0, 0), (-1, -1), 0), #('BOX', (0,0), (-1, -1), 0.25, colors.black), #('ALIGN', (0,0), (-1, 0), 'LEFT') ]), ) ]) #vats = [(25, decimal.Decimal('11.37')), (12, decimal.Decimal('6.78'))] for code, percentage, amount in purchase.vat: tabledata.append([ Table( [[ '', Paragraph( _('Including %s%% VAT') % py3txt(formatters.vatpercentage(percentage)), boldrightstyle), Paragraph(formatters.money(amount, True), boldrightstyle) ]], colWidths=[115 * mm, 40 * mm, 25 * mm], style=TableStyle([ ('ALIGN', (1, 0), (-1, -1), 'RIGHT'), ('TOPPADDING', (0, 0), (-1, -1), 0), ('BOTTOMPADDING', (0, 0), (-1, -1), 0), #('BOX', (0,0), (-1, -1), 0.25, colors.black), #('ALIGN', (0,0), (-1, 0), 'LEFT') ]), ) ]) t = Table( [[t] for t in tabledata], colWidths=[180 * mm], repeatRows=1, style=TableStyle([ ('LEFTPADDING', (0, 0), (0, -1), 0), ('RIGHTPADDING', (0, -1), (-1, -1), 0), #('BOX', (0,0), (-1, -1), 0.25, colors.black) ])) elements.append(t) extraText = purchase.extraText if extraText: textElements = [] text_style = ParagraphStyle('Text', fontName='Helvetica', fontSize=8, leading=9) for text in extraText: textElements.append(Paragraph(text, text_style)) elements.append(KeepTogether(textElements)) doc.multiBuild(elements)
def _breakingTestCase(self): "This makes one long multi-page paragraph." # Build story. story = [] def fbreak(story=story): story.append(FrameBreak()) styleSheet = getSampleStyleSheet() H1 = styleSheet['Heading1'] H1.pageBreakBefore = 0 H1.keepWithNext = 0 bt = styleSheet['BodyText'] pto = ParagraphStyle('pto',parent=bt) pto.alignment = TA_RIGHT pto.fontSize -= 1 def ColorParagraph(c,text,style): return Paragraph('<para color=%s>%s</para>' % (c,text),style) def ptoblob(blurb,content,trailer=None,header=None, story=story, H1=H1): if type(content) not in (type([]),type(())): content = [content] story.append(PTOContainer([Paragraph(blurb,H1)]+list(content),trailer,header)) text2 ='''We have already seen that the natural general principle that will subsume this case cannot be arbitrary in the requirement that branching is not tolerated within the dominance scope of a complex symbol. Notice, incidentally, that the speaker-hearer's linguistic intuition is to be regarded as the strong generative capacity of the theory. A consequence of the approach just outlined is that the descriptive power of the base component does not affect the structure of the levels of acceptability from fairly high (e.g. (99a)) to virtual gibberish (e.g. (98d)). By combining adjunctions and certain deformations, a descriptively adequate grammar cannot be arbitrary in the strong generative capacity of the theory.''' text1=''' On our assumptions, a descriptively adequate grammar delimits the strong generative capacity of the theory. For one thing, the fundamental error of regarding functional notions as categorial is to be regarded as a corpus of utterance tokens upon which conformity has been defined by the paired utterance test. A majority of informed linguistic specialists agree that the appearance of parasitic gaps in domains relatively inaccessible to ordinary extraction is necessary to impose an interpretation on the requirement that branching is not tolerated within the dominance scope of a complex symbol. It may be, then, that the speaker-hearer's linguistic intuition appears to correlate rather closely with the ultimate standard that determines the accuracy of any proposed grammar. Analogously, the notion of level of grammaticalness may remedy and, at the same time, eliminate a general convention regarding the forms of the grammar.''' text0 = '''To characterize a linguistic level L, this selectionally introduced contextual feature delimits the requirement that branching is not tolerated within the dominance scope of a complex symbol. Notice, incidentally, that the notion of level of grammaticalness does not affect the structure of the levels of acceptability from fairly high (e.g. (99a)) to virtual gibberish (e.g. (98d)). Suppose, for instance, that a subset of English sentences interesting on quite independent grounds appears to correlate rather closely with an important distinction in language use. Presumably, this analysis of a formative as a pair of sets of features is not quite equivalent to the system of base rules exclusive of the lexicon. We have already seen that the appearance of parasitic gaps in domains relatively inaccessible to ordinary extraction does not readily tolerate the strong generative capacity of the theory.''' t0 = [ColorParagraph('blue','Please turn over', pto )] h0 = [ColorParagraph('blue','continued from previous page', pto )] t1 = [ColorParagraph('red','Please turn over(inner)', pto )] h1 = [ColorParagraph('red','continued from previous page(inner)', pto )] ptoblob('First Try at a PTO',[Paragraph(text0,bt)],t0,h0) fbreak() c1 = Table([('alignment', 'align\012alignment'), ('bulletColor', 'bulletcolor\012bcolor'), ('bulletFontName', 'bfont\012bulletfontname'), ('bulletFontSize', 'bfontsize\012bulletfontsize'), ('bulletIndent', 'bindent\012bulletindent'), ('firstLineIndent', 'findent\012firstlineindent'), ('fontName', 'face\012fontname\012font'), ('fontSize', 'size\012fontsize'), ('leading', 'leading'), ('leftIndent', 'leftindent\012lindent'), ('rightIndent', 'rightindent\012rindent'), ('spaceAfter', 'spaceafter\012spacea'), ('spaceBefore', 'spacebefore\012spaceb'), ('textColor', 'fg\012textcolor\012color')], style = [ ('VALIGN',(0,0),(-1,-1),'TOP'), ('INNERGRID', (0,0), (-1,-1), 0.25, black), ('BOX', (0,0), (-1,-1), 0.25, black), ], ) ptoblob('PTO with a table inside',c1,t0,h0) fbreak() ptoblob('A long PTO',[Paragraph(text0+' '+text1,bt)],t0,h0) fbreak() ptoblob('2 PTO (inner split)',[ColorParagraph('pink',text0,bt),PTOContainer([ColorParagraph(black,'Inner Starts',H1),ColorParagraph('yellow',text2,bt),ColorParagraph('black','Inner Ends',H1)],t1,h1),ColorParagraph('magenta',text1,bt)],t0,h0) pageTemplate = PageTemplate('normal', [Frame(2.5*cm, 15.5*cm, 6*cm, 10*cm, id='F1'), Frame(11.5*cm, 15.5*cm, 6*cm, 10*cm, id='F2'), Frame(2.5*cm, 2.5*cm, 6*cm, 10*cm, id='F3'), Frame(11.5*cm, 2.5*cm, 6*cm, 10*cm, id='F4'), ], myMainPageFrame) doc = BaseDocTemplate(outputfile('test_platypus_pto.pdf'), pageTemplates = pageTemplate, showBoundary = 1, ) doc.multiBuild(story)
def multiBuild(self, flowables,onFirstPage=_doNothing, onLaterPages=_doNothing, canvasmaker=canvas.Canvas): BaseDocTemplate.multiBuild(self,flowables, canvasmaker=canvasmaker)