def _print_reference(self): index = SimpleIndex() index.setup(self._styles['root']) self._story.append(NextPageTemplate('SimpleIndex')) self._story.append(PageBreak()) self._story.append(RLParagraph(self.TITLE_INDEX, self._styles['h3'])) self._story.append(index) return index.getCanvasMaker()
def _print_reference(self): index = SimpleIndex() index.setup(self._styles['root']) self._story.append(NextPageTemplate('SimpleIndex')) self._story.append(PageBreak()) self._story.append(RLParagraph(self.TITLE_INDEX, self._styles['h3'])) self._story.append(index) return index.getCanvasMaker()
def test0(self): ''' Test case for Indexes. This will draw an index %sat the end of the document with dots seperating the indexing terms from the page numbers. Index terms are grouped by their first 2, and first 3 characters. The page numbers should be clickable and link to the indexed word. ''' # Build story. for headers in False, True: path = outputfile('test_platypus_index%s.pdf' % (headers and '_headers' or '')) doc = MyDocTemplate(path) story = [] styleSheet = getSampleStyleSheet() bt = styleSheet['BodyText'] description = '<font color=red>%s</font>' % (self.test0.__doc__ % (headers and 'with alphabetic headers ' or '')) story.append(Paragraph(description, bt)) index = SimpleIndex(dot=' . ', headers=headers) def addParas(words): words = [asUnicode(w) for w in words] txt = u' '.join([(len(w) > 5 and u'<index item=%s/>%s' % (quoteattr(commajoin([w[:2], w[:3], w])), w) or w) for w in words]) para = Paragraph(txt, makeBodyStyle()) story.append(para) for i in xrange(20): addParas(randomtext.randomText(randomtext.PYTHON, 5).split(' ')) addParas([u+w for u in u'E\xc8\xc9\xca\xcb' for w in (u'erily',u'asily')]) addParas([u+w for u in u'A\xc0\xc4\xc1\xc3\xc2' for w in (u'dvance',u'ttend')]) addParas([u+w for u in u'O\xd2\xd6\xd3\xd2' for w in (u'rdinary',u'verflow')]) addParas([u+w for u in u'U\xd9\xdc\xdb' for w in (u'ndertow',u'nbeliever')]) addParas([u+w for u in u'e\xe8\xea\xeb\xe9' for w in (u'ventide',u'lision')]) addParas([u+w for u in u'o\xf2\xf5\xf3\xf4' for w in (u'verture',u'ntology')]) #test ampersand in index term txt = '\nMarks & Spencer - purveyors of fine groceries, underwear and ampersands - should have their initials displayed however they were input.\n<index item="M&S,groceries"/><index item="M&S,underwear"/><index item="M&S,ampersands"/>' para = Paragraph(txt, makeBodyStyle()) story.append(para) story.append(index) doc.build(story, canvasmaker=index.getCanvasMaker())
def simple_index(): doc = SimpleDocTemplate("simple_index.pdf", pagesize=letter) styles = getSampleStyleSheet() flowables = [] ptext = """I'm a custom <index item="bulletted"/>bulletted paragraph""" para = Paragraph(ptext, style=styles["Normal"], bulletText='-') flowables.append(para) flowables.append(PageBreak()) ptext = """<index item="Python"/>Python is an indexed word""" para = Paragraph(ptext, style=styles["Normal"], bulletText='-') flowables.append(para) index = SimpleIndex() flowables.append(PageBreak()) flowables.append(index) doc.build(flowables, canvasmaker=index.getCanvasMaker())
def test0(self): """ Test case for Indexes. This will draw an index %sat the end of the document with dots seperating the indexing terms from the page numbers. Index terms are grouped by their first 2, and first 3 characters. The page numbers should be clickable and link to the indexed word. """ # Build story. for headers in False, True: path = outputfile("test_platypus_index%s.pdf" % (headers and "_headers" or "")) doc = MyDocTemplate(path) story = [] styleSheet = getSampleStyleSheet() bt = styleSheet["BodyText"] description = "<font color=red>%s</font>" % ( self.test0.__doc__ % (headers and "with alphabetic headers " or "") ) story.append(Paragraph(description, bt)) index = SimpleIndex(dot=" . ", headers=headers) for i in range(20): words = randomtext.randomText(randomtext.PYTHON, 5).split(" ") txt = " ".join( [ (len(w) > 5 and "<index item=%s/>%s" % (quoteattr(commajoin([w[:2], w[:3], w])), w) or w) for w in words ] ) para = Paragraph(txt, makeBodyStyle()) story.append(para) # test ampersand in index term txt = '\nMarks & Spencer - purveyors of fine groceries, underwear and ampersands - should have their initials displayed however they were input.\n<index item="M&S,groceries"/><index item="M&S,underwear"/><index item="M&S,ampersands"/>' para = Paragraph(txt, makeBodyStyle()) story.append(para) story.append(index) doc.build(story, canvasmaker=index.getCanvasMaker())
def test0(self): ''' Test case for Indexes. This will draw an index %sat the end of the document with dots seperating the indexing terms from the page numbers. Index terms are grouped by their first 2, and first 3 characters. The page numbers should be clickable and link to the indexed word. ''' # Build story. for headers in False, True: path = outputfile('test_platypus_index%s.pdf' % (headers and '_headers' or '')) doc = MyDocTemplate(path) story = [] styleSheet = getSampleStyleSheet() bt = styleSheet['BodyText'] description = '<font color=red>%s</font>' % ( self.test0.__doc__ % (headers and 'with alphabetic headers ' or '')) story.append(Paragraph(description, bt)) index = SimpleIndex(dot=' . ', headers=headers) for i in range(20): words = randomtext.randomText(randomtext.PYTHON, 5).split(' ') txt = ' '.join([(len(w) > 5 and '<index item=%s/>%s' % (quoteattr(commajoin([w[:2], w[:3], w])), w) or w) for w in words]) para = Paragraph(txt, makeBodyStyle()) story.append(para) #test ampersand in index term txt = '\nMarks & Spencer - purveyors of fine groceries, underwear and ampersands - should have their initials displayed however they were input.\n<index item="M&S,groceries"/><index item="M&S,underwear"/><index item="M&S,ampersands"/>' para = Paragraph(txt, makeBodyStyle()) story.append(para) story.append(index) doc.build(story, canvasmaker=index.getCanvasMaker())
this is sample <index item="index"/> without index """ p_text = Paragraph(text, style=styles["Normal"]) text1 = """ this is sample <index item="reportlab"/> with reportlab index """ p_text1 = Paragraph(text1, style=styles["Normal"]) text2 = """ this is sample <index item="flowable"/> flowable index """ p_text2 = Paragraph(text2, style=styles["Normal"]) index = SimpleIndex() for i in range(1, 4): flow_obj.append(p_text) flow_obj.append(PageBreak()) for i in range(1, 4): flow_obj.append(p_text1) flow_obj.append(PageBreak()) for i in range(1, 4): flow_obj.append(p_text2) flow_obj.append(PageBreak()) flow_obj.append(index) pdf.build(flow_obj, canvasmaker=index.getCanvasMaker())