Python reportlab.platypus.TableStyle() Examples

The following are 18 code examples of reportlab.platypus.TableStyle(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module reportlab.platypus , or try the search function .
Example #1
Source File: genelements.py    From rst2pdf with MIT License 5 votes vote down vote up
def gather_elements(self, client, node, style):
        # Multiple authors. Create a two-column table.
        # Author references on the right.
        t_style = TableStyle(client.styles['field-list'].commands)
        colWidths = client.styles['field-list'].colWidths

        td = [
            [
                Paragraph(
                    client.text_for_label("authors", style) + ":",
                    style=client.styles['fieldname'],
                ),
                client.gather_elements(node, style=style),
            ]
        ]
        return [DelayedTable(td, style=t_style, colWidths=colWidths)] 
Example #2
Source File: sphinxnodes.py    From rst2pdf with MIT License 5 votes vote down vote up
def gather_elements(self, client, node, style):
        # Each child is a hlistcol and represents a column.
        # Each grandchild is a bullet list that's the contents
        # of the column

        # Represent it as a N-column, 1-row table, each cell containing
        # a list.

        cells = [[client.gather_elements(child, style) for child in node.children]]
        t_style = TableStyle(client.styles['hlist'].commands)
        cw = 100.0 / len(node.children)
        return [
            DelayedTable(cells, colWidths=["%s%%" % cw,] * len(cells), style=t_style)
        ] 
Example #3
Source File: genelements.py    From rst2pdf with MIT License 5 votes vote down vote up
def gather_elements(self, client, node, style):
        rows = [client.gen_elements(n) for n in node.children]
        t = []
        for r in rows:
            if not r:
                continue
            t.append(r)
        t_style = TableStyle(client.styles['table'].commands)
        colWidths = client.styles['table'].colWidths
        return [DelayedTable(t, style=t_style, colWidths=colWidths)] 
Example #4
Source File: genelements.py    From rst2pdf with MIT License 5 votes vote down vote up
def gather_elements(self, client, node, style):

        # Either use the figure style or the class
        # selected by the user
        st_name = 'figure'
        if node.get('classes'):
            st_name = node.get('classes')[0]
        style = client.styles[st_name]
        cmd = getattr(style, 'commands', [])
        image = node.children[0]
        if len(node.children) > 1:
            caption = node.children[1]
        else:
            caption = None

        if len(node.children) > 2:
            legend = node.children[2:]
        else:
            legend = []

        w = node.get('width', client.styles['figure'].colWidths[0])
        cw = [
            w,
        ]
        sub_elems = client.gather_elements(node, style=None)
        t_style = TableStyle(cmd)
        table = DelayedTable([[e,] for e in sub_elems], style=t_style, colWidths=cw)
        table.hAlign = node.get('align', 'CENTER').upper()
        return [
            MySpacer(0, style.spaceBefore),
            table,
            MySpacer(0, style.spaceAfter),
        ] 
Example #5
Source File: genelements.py    From rst2pdf with MIT License 5 votes vote down vote up
def gather_elements(self, client, node, style):
        # I need to catch the classifiers here
        tt = []
        dt = []
        ids = []
        for n in node.children:
            if isinstance(n, docutils.nodes.term):
                for i in n['ids']:  # Used by sphinx glossary lists
                    if i not in client.targets:
                        ids.append('<a name="%s"/>' % i)
                        client.targets.append(i)
                o, c = client.styleToTags("definition-list-term")
                tt.append(o + client.gather_pdftext(n) + c)
            elif isinstance(n, docutils.nodes.classifier):
                o, c = client.styleToTags("definition-list-classifier")
                tt.append(o + client.gather_pdftext(n) + c)
            else:
                dt.extend(client.gen_elements(n, style))

        # FIXME: make this configurable from the stylesheet
        t_style = TableStyle(client.styles['definition'].commands)
        cw = getattr(client.styles['definition'], 'colWidths', [])

        if client.splittables:
            node.elements = [
                Paragraph(
                    ''.join(ids) + ' : '.join(tt),
                    client.styles['definition-list-term'],
                ),
                SplitTable([['', dt]], colWidths=cw, style=t_style),
            ]
        else:
            node.elements = [
                Paragraph(
                    ''.join(ids) + ' : '.join(tt),
                    client.styles['definition-list-term'],
                ),
                DelayedTable([['', dt]], colWidths=[10, None], style=t_style),
            ]

        return node.elements 
Example #6
Source File: genelements.py    From rst2pdf with MIT License 5 votes vote down vote up
def gather_elements(self, client, node, style):
        fb = client.gather_pdftext(node)
        t_style = TableStyle(client.styles['field-list'].commands)
        colWidths = client.styles['field-list'].colWidths
        if self.adjustwidths:
            colWidths = [client.styles.adjustUnits(x) for x in colWidths]
        label = client.text_for_label(self.labeltext, style) + ":"
        t = self.TableType(
            [
                [
                    Paragraph(label, style=client.styles['fieldname']),
                    XPreformatted(fb, style),
                ]
            ],
            style=t_style,
            colWidths=colWidths,
        )
        return [t] 
Example #7
Source File: genelements.py    From rst2pdf with MIT License 5 votes vote down vote up
def gather_elements(self, client, node, style):
        fb = client.gather_pdftext(node)
        t_style = TableStyle(client.styles['field-list'].commands)
        colWidths = client.styles['field-list'].colWidths
        if self.adjustwidths:
            colWidths = [client.styles.adjustUnits(x) for x in colWidths]
        label = client.text_for_label(self.labeltext, style) + ":"
        t = self.TableType(
            [
                [
                    Paragraph(label, style=client.styles['fieldname']),
                    Paragraph(fb, style),
                ]
            ],
            style=t_style,
            colWidths=colWidths,
        )
        return [t] 
Example #8
Source File: letters.py    From coursys with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, to_addr_lines, from_name_lines, date=None,
                 closing="Yours truly", signer=None, paragraphs=None, cosigner_lines=None, use_sig=True,
                 body_font_size=None, cc_lines=None):
        self.date = date or datetime.date.today()
        self.closing = closing
        self.flowables = []
        self.to_addr_lines = to_addr_lines
        self.from_name_lines = from_name_lines
        self.cosigner_lines = cosigner_lines
        self.signer = signer
        self.use_sig = use_sig
        if cc_lines:
            self.cc_lines = [cc for cc in cc_lines if cc.strip()]
        else:
            self.cc_lines = None
        if paragraphs:
            self.add_paragraphs(paragraphs)

        # styles
        self.line_height = (body_font_size or 12) + 1
        self.content_style = ParagraphStyle(name='Normal',
                                            fontName='BemboMTPro',
                                            fontSize=body_font_size or 12,
                                            leading=self.line_height,
                                            allowWidows=0,
                                            allowOrphans=0,
                                            alignment=TA_JUSTIFY,
                                            textColor=black)
        self.table_style = TableStyle([
                    ('FONT', (0,0), (-1,-1), 'BemboMTPro', 12, self.line_height),
                    ('TOPPADDING', (0,0), (-1,-1), 0),
                    ('BOTTOMPADDING', (0,0), (-1,-1), 0),
                    ]) 
Example #9
Source File: genelements.py    From rst2pdf with MIT License 5 votes vote down vote up
def gather_elements(self, client, node, style):
        if isinstance(node.parent, docutils.nodes.authors):
            # Is only one of multiple authors. Return a paragraph
            node.elements = [Paragraph(client.gather_pdftext(node), style=style)]
            if client.doc_author:
                client.doc_author += (
                    client.author_separator(style=style) + node.astext().strip()
                )
            else:
                client.doc_author = node.astext().strip()
        else:
            # A single author: works like a field
            fb = client.gather_pdftext(node)

            t_style = TableStyle(client.styles['field-list'].commands)
            colWidths = [
                client.styles.adjustUnits(x)
                for x in client.styles['field-list'].colWidths
            ]

            node.elements = [
                Table(
                    [
                        [
                            Paragraph(
                                client.text_for_label("author", style) + ":",
                                style=client.styles['fieldname'],
                            ),
                            Paragraph(fb, style),
                        ]
                    ],
                    style=t_style,
                    colWidths=colWidths,
                )
            ]
            client.doc_author = node.astext().strip()
        return node.elements 
Example #10
Source File: genelements.py    From rst2pdf with MIT License 5 votes vote down vote up
def gather_elements(self, client, node, style):
        # A field has two child elements, a field_name and a field_body.
        # We render as a two-column table, left-column is right-aligned,
        # bold, and much smaller

        fn = Paragraph(
            client.gather_pdftext(node.children[0]) + ":",
            style=client.styles['fieldname'],
        )
        fb = client.gen_elements(node.children[1], style=client.styles['fieldvalue'])
        t_style = TableStyle(client.styles['field-list'].commands)
        return [
            DelayedTable(
                [[fn, fb]],
                style=t_style,
                colWidths=client.styles['field-list'].colWidths,
            )
        ] 
Example #11
Source File: table.py    From tia with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def style_and_data(self):
        if self._style_and_data is None:
            data = self.tb.formatted_values.values.tolist()
            style = TableStyle(self.tb.style_cmds)
            self._style_and_data = style, data
        return self._style_and_data 
Example #12
Source File: pdf.py    From correios with Apache License 2.0 5 votes vote down vote up
def _posting_list_table(self, canvas, x1, y1, x2, y2, shipping_labels):
        style = self.table_style[:]
        table = [self.table_header]
        for i, shipping_label in enumerate(shipping_labels, start=1):
            row = (
                str(shipping_label.tracking_code),
                str(shipping_label.receiver.zip_code),
                str(shipping_label.package.weight),
                self.yes if ExtraService.get(EXTRA_SERVICE_AR) in shipping_label else self.no,
                self.yes if ExtraService.get(EXTRA_SERVICE_MP) in shipping_label else self.no,
                self.yes if shipping_label.has_declared_value() else self.no,
                str(shipping_label.value).replace(".", ",") if shipping_label.value is not None else "",
                str(shipping_label.invoice_number),
                shipping_label.get_package_sequence(),
                shipping_label.receiver.name[: self.max_receiver_name_size],
            )

            # noinspection PyTypeChecker
            table.append(row)

            if i % 2:
                style.append(("BACKGROUND", (0, i), (-1, i), colors.lightgrey))

        table_flow = Table(table, colWidths=self.col_widths, style=TableStyle(style))
        w, h = table_flow.wrap(0, 0)
        table_flow.drawOn(canvas, x1, y2 - h - 50 * mm) 
Example #13
Source File: components.py    From HH---POS-Accounting-and-ERP-Software with MIT License 5 votes vote down vote up
def __init__(self, data, horizontal_align=None, style=None):
        Table.__init__(self, data, hAlign=horizontal_align)

        default_style = [
            ('INNERGRID', (0, 0), (-1, -1), .25, colors.black),
            ('BOX', (0, 0), (-1, -1), .25, colors.black),
            ('BACKGROUND', (0, 0), (-1, -len(data)), colors.lightgrey),
            ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
            ('VALIGN', (0, 0), (-1, -1), 'MIDDLE')
        ]

        if style and isinstance(style, list):
            default_style.extend(style)

        self.setStyle(TableStyle(default_style)) 
Example #14
Source File: components.py    From PyInvoice with MIT License 5 votes vote down vote up
def __init__(self, data, horizontal_align=None, style=None):
        Table.__init__(self, data, hAlign=horizontal_align)

        default_style = [
            ('INNERGRID', (0, 0), (-1, -1), .25, colors.black),
            ('BOX', (0, 0), (-1, -1), .25, colors.black),
            ('BACKGROUND', (0, 0), (-1, -len(data)), colors.lightgrey),
            ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
            ('VALIGN', (0, 0), (-1, -1), 'MIDDLE')
        ]

        if style and isinstance(style, list):
            default_style.extend(style)

        self.setStyle(TableStyle(default_style)) 
Example #15
Source File: letters.py    From coursys with GNU General Public License v3.0 5 votes vote down vote up
def _contents(self, memo):
        """
        Produce a list of Flowables to form the body of the memo
        """
        contents = []
        space_height = self.line_height
        # the header block
        contents.append(MemoHead(key='Attention', value=', '.join(self.to_addr_lines), bold=True))
        contents.append(MemoHead(key='From', value=', '.join(self.from_name_lines)))
        contents.append(MemoHead(key='Re', value=self.subject[0]))
        for subjectline in self.subject[1:]:
            contents.append(MemoHead(key='', value=subjectline))
        contents.append(MemoHead(key='Date', value=self.date.strftime('%B %d, %Y').replace(' 0', ' ')))
        contents.append(Spacer(1, 2*space_height))

        # insert each paragraph
        for f in self.flowables:
            contents.append(f)
            #contents.append(Spacer(1, space_height))

        # the CC lines
        if self.cc_lines:
            data = []
            for cc in self.cc_lines:
                data.append(['', Paragraph(cc, self.content_style)])

            cc = Paragraph('cc:', self.content_style)
            data[0][0] = cc

            cc_table = Table(data, colWidths=[0.3 * inch, 5 * inch])
            cc_table.hAlign = "LEFT"
            cc_table.setStyle(TableStyle(
                [('LEFTPADDING', (0, 0), (-1, -1), 0),
                 ('RIGHTPADDING', (0, 0), (-1, -1), 0),
                 ('TOPPADDING', (0, 0), (-1, -1), 0),
                 ('BOTTOMPADDING', (0, 0), (-1, -1), 0)]))

            contents.append(cc_table)
        return contents 
Example #16
Source File: genelements.py    From rst2pdf with MIT License 4 votes vote down vote up
def gather_elements(self, client, node, style):
        # This should work, but doesn't look good inside of
        # table cells (see Issue 173)
        # node.elements = [MyIndenter(left=client.styles['blockquote'].leftIndent)]\
        # + client.gather_elements( node, style) + \
        # [MyIndenter(left=-client.styles['blockquote'].leftIndent)]
        # Workaround for Issue 173 using tables
        leftIndent = client.styles['blockquote'].leftIndent
        rightIndent = client.styles['blockquote'].rightIndent
        spaceBefore = client.styles['blockquote'].spaceBefore
        spaceAfter = client.styles['blockquote'].spaceAfter
        s = copy(client.styles['blockquote'])
        s.leftIndent = style.leftIndent
        data = [['', client.gather_elements(node, s)]]
        if client.splittables:
            node.elements = [
                MySpacer(0, spaceBefore),
                SplitTable(
                    data,
                    colWidths=[leftIndent, None],
                    style=TableStyle(
                        [
                            ["TOPPADDING", [0, 0], [-1, -1], 0],
                            ["LEFTPADDING", [0, 0], [-1, -1], 0],
                            ["RIGHTPADDING", [0, 0], [-1, -1], rightIndent],
                            ["BOTTOMPADDING", [0, 0], [-1, -1], 0],
                        ]
                    ),
                ),
                MySpacer(0, spaceAfter),
            ]
        else:
            node.elements = [
                MySpacer(0, spaceBefore),
                DelayedTable(
                    data,
                    colWidths=[leftIndent, None],
                    style=TableStyle(
                        [
                            ["TOPPADDING", [0, 0], [-1, -1], 0],
                            ["LEFTPADDING", [0, 0], [-1, -1], 0],
                            ["RIGHTPADDING", [0, 0], [-1, -1], rightIndent],
                            ["BOTTOMPADDING", [0, 0], [-1, -1], 0],
                        ]
                    ),
                ),
                MySpacer(0, spaceAfter),
            ]
        return node.elements 
Example #17
Source File: fd_api_doc.py    From Fluid-Designer with GNU General Public License v3.0 4 votes vote down vote up
def create_hdr(self, name, font_size):
        hdr_style = TableStyle([('TEXTCOLOR', (0, 0), (-1, -1), colors.black),
                                ('BOTTOMPADDING', (0, 0), (-1, -1), 15),
                                ('TOPPADDING', (0, 0), (-1, -1), 15),
                                ('FONTSIZE', (0, 0), (-1, -1), 8),
                                ('VALIGN', (0, 0), (-1, -1), 'TOP'),
                                ('ALIGN', (0, 0), (-1, 0), 'LEFT'),
                                ('LINEBELOW', (0, 0), (-1, -1), 2, colors.black),
                                ('BACKGROUND', (0, 1), (-1, -1), colors.white)])        
        
        name_p = Paragraph(name, ParagraphStyle("Category name style", fontSize=font_size))
        hdr_tbl = Table([[name_p]], colWidths = 500, rowHeights = None, repeatRows = 1)
        hdr_tbl.setStyle(hdr_style)
        self.elements.append(hdr_tbl) 
Example #18
Source File: genelements.py    From rst2pdf with MIT License 4 votes vote down vote up
def gather_elements(self, client, node, style):
        # It seems a footnote contains a label and a series of elements
        ltext = client.gather_pdftext(node.children[0])
        label = None
        ids = ''
        for i in node.get('ids', []):
            ids += '<a name="%s"/>' % (i)
        client.targets.extend(node.get('ids', [ltext]))

        if len(node['backrefs']) > 1 and client.footnote_backlinks:
            backrefs = []
            i = 1
            for r in node['backrefs']:
                backrefs.append(
                    '<a href="#%s" color="%s">%d</a>' % (r, client.styles.linkColor, i)
                )
                i += 1
            backrefs = '(%s)' % ', '.join(backrefs)
            if ltext not in client.targets:
                label = Paragraph(
                    ids + '%s' % (ltext + backrefs), client.styles["endnote"]
                )
                client.targets.append(ltext)
        elif len(node['backrefs']) == 1 and client.footnote_backlinks:
            if ltext not in client.targets:
                label = Paragraph(
                    ids
                    + '<a href="#%s" color="%s">%s</a>'
                    % (node['backrefs'][0], client.styles.linkColor, ltext),
                    client.styles["endnote"],
                )
                client.targets.append(ltext)
        else:
            if ltext not in client.targets:
                label = Paragraph(ids + ltext, client.styles["endnote"])
                client.targets.append(ltext)
        if not label:
            label = Paragraph(ids + ltext, client.styles["endnote"])
        contents = client.gather_elements(node, client.styles["endnote"])[1:]
        if client.inline_footnotes:
            st = client.styles['endnote']
            t_style = TableStyle(st.commands)
            colWidths = client.styles['endnote'].colWidths
            node.elements = [
                MySpacer(0, st.spaceBefore),
                DelayedTable([[label, contents]], style=t_style, colWidths=colWidths),
                MySpacer(0, st.spaceAfter),
            ]
            if client.real_footnotes:
                client.mustMultiBuild = True
                for e in node.elements:
                    e.isFootnote = True
        else:
            client.decoration['endnotes'].append([label, contents])
            node.elements = []
        return node.elements