def test0(self):
        "This makes one long multi-page paragraph."

        # Build story.
        story = []
        styleSheet = getSampleStyleSheet()
        bt = styleSheet['BodyText']
        text = '''If you imagine that the box of X's tothe left is
an image, what I want to be able to do is flow a
series of paragraphs around the image
so that once the bottom of the image is reached, then text will flow back to the
left margin. I know that it would be possible to something like this
using tables, but I can't see how to have a generic solution.
There are two examples of this in the demonstration section of the reportlab
site.
If you look at the "minimal" euro python conference brochure, at the end of the
timetable section (page 8), there are adverts for "AdSu" and "O'Reilly". I can
see how the AdSu one might be done generically, but the O'Reilly, unsure...
I guess I'm hoping that I've missed something, and that
it's actually easy to do using platypus.
'''
        from reportlab.platypus.flowables import ParagraphAndImage, Image
        from reportlab.lib.testutils import testsFolder
        gif = os.path.join(testsFolder,'pythonpowered.gif')
        story.append(ParagraphAndImage(Paragraph(text,bt),Image(gif)))
        phrase = 'This should be a paragraph spanning at least three pages. '
        description = ''.join([('%d: '%i)+phrase for i in xrange(250)])
        story.append(ParagraphAndImage(Paragraph(description, bt),Image(gif),side='left'))

        doc = MyDocTemplate(outputfile('test_platypus_paragraphandimage.pdf'))
        doc.multiBuild(story)
Ejemplo n.º 2
0
 def fill_sender(self):
     """Fills sender identity"""
     from reportlab.platypus.flowables import Image
     from core.pdf.utils import Paragraph
     # Sender identity
     sender_paragraphs = []
     if self.invoice_base.current_revision.sender:
         sender_paragraphs.append(
             Paragraph(self.invoice_base.current_revision.sender,
                       self.style['Small']))
     sender_paragraphs.append(
         Paragraph(self.invoice_base.tenant.name, self.style['Small']))
     if self.invoice_base.current_revision.sender_address:
         sender_paragraphs.append(
             Paragraph(
                 u'\n'.join(self.invoice_base.current_revision.
                            sender_address.get_formatted()),
                 self.style['Small']))
     # Add layout table if logo or paragraphs
     if self.invoice_base.tenant.logo_cache:
         logo = Image(self.invoice_base.tenant.logo_cache)
         logo_width, logo_height = logo._restrictSize(50 * mm, 20 * mm)
         self.table([[logo, sender_paragraphs]],
                    (logo_width + 4 * mm, None),
                    self.style['LayoutTable'],
                    rowHeights=(20 * mm, ))
     else:
         for paragraph in sender_paragraphs:
             self.append(paragraph)
Ejemplo n.º 3
0
    def myFirstPage(self, canvas, doc):
        Image('PhEDEx-banner.png', width=A4[0],
              height=100).drawOn(canvas, 0, (A4[1] - 100))
        self.allPages(canvas, doc)

        style = self.getStyle()
        date = self.getDate()
        P = Paragraph("%s PhEDEx Report" % self.site, style["ReportTitle"])
        size = P.wrap(A4[0], 200)
        #Because we're drawing 'raw' paragraphs need to wrap them
        P.wrapOn(canvas, A4[0], size[1])
        top = 10 + size[1]
        P.drawOn(canvas, 0, A4[1] - top)

        P = Paragraph("Week beginning %s" % date, style["ReportTitleDate"])
        size = P.wrap(A4[0], 200)
        P.wrapOn(canvas, A4[0], size[1])
        top = top + size[1]
        P.drawOn(canvas, 0, A4[1] - top)

        P = Paragraph("%s Instance" % self.instance, style["ReportSubTitle"])
        size = P.wrap(A4[0], 200)
        P.wrapOn(canvas, A4[0], size[1])
        top = top + size[1]
        P.drawOn(canvas, 0, A4[1] - top)
Ejemplo n.º 4
0
    def doSubscriptions(self):
        style = self.getStyle()
        text = """There have been 21 subscription requests this week. 
        All have been approved| X were approved, Y rejected, 
        Z are still to be considered. """

        png = 'Picture 1.png'

        subscriptionsPara = [
            Spacer(inch * .25, inch * .25),
            Paragraph('Subscriptions', style['SectionTitle']),
            Paragraph(text, style=style["Normal_just_rind"]),
            Spacer(inch * .125, inch * .125),
            Paragraph(self.doRequests(), style=style["Normal_just_rind"]),
            Spacer(inch * .25, inch * .25)
        ]
        subscriptionsImg = ImageAndFlowables(Image(png, width=180, height=180),
                                             subscriptionsPara,
                                             imageLeftPadding=0,
                                             imageRightPadding=0,
                                             imageSide='right')

        return KeepTogether(
            [subscriptionsImg,
             Spacer(inch * .125, inch * .125)])
Ejemplo n.º 5
0
 def reportHeader(self):
     
     reportLogo = Image(self.app.engine.logo)
     reportLogo.drawHeight = 0.80 * inch 
     reportLogo.drawWidth =  1.20 * inch
     
     t = Table((('Data Report','',[reportLogo]),
                ("Start Date",self.start_date.strftime('%d/%m/%Y'),''),
                ("Category",self.category,''),
                ("Supplier",self.supplier,''),
                ("Records",len(self.rs),'')),
               #colWidths, rowHeights,
               (80,80,250),
               (18,18,18,18,18,))
     #('SPAN',(2,0),(2,-1)) expand image
     t.setStyle(TableStyle([#column, row
                            ('SPAN',(2,0),(2,-1)),
                            ('BOX',(0,1),(1,-1),0.5,colors.lightgrey),
                            ('LINEABOVE',(0,-1),(1,-1),0.5,colors.lightgrey),
                            ('TEXTCOLOR', (1,1),(1,-3),colors.red, 10),
                            ('TEXTCOLOR', (1,1),(1,-4),colors.blue, 10),
                            #('GRID',(0,1),(1,-1), 0.2, colors.black),
                            ('ALIGN',(1,0),(-1,-1),'CENTER'),
                            ('FONT', (0,0),(0,0),'Times-Bold', 18),]))
     return t
Ejemplo n.º 6
0
    def draw_header(self):
        if self.preview:
            t = self.canvas.beginText()
            t.setTextOrigin(cm(6), cm(4))
            t.setFont("DejaVu Serif Italic", 70)
            t.setFillColorRGB(0.9, 0.9, 0.9)
            t.textLine("PREVIEW PREVIEW")
            self.canvas.rotate(45)
            self.canvas.drawText(t)
            self.canvas.rotate(-45)

        if self.logo:
            im = Image(self.logo, width=cm(3), height=cm(3))
            im.drawOn(self.canvas, cm(2), cm(25))

        if self.headertext:
            t = self.canvas.beginText()
            t.setFillColor(colors.black)
            t.setFont("DejaVu Serif", 9)
            t.setTextOrigin(cm(6), cm(27.5))
            self.textlines(t, self.headertext)
            self.canvas.drawText(t)

        if self.sendertext:
            self._draw_multiline_aligned(self.sendertext,
                                         cm(2), cm(23.5), cm(9), cm(4))

        self._draw_multiline_aligned("To:\n%s" % self.recipient,
                                     cm(11), cm(23.5), cm(9), cm(4))

        p = self.canvas.beginPath()
        p.moveTo(cm(2), cm(18.9))
        p.lineTo(cm(19), cm(18.9))
        self.canvas.drawPath(p)
Ejemplo n.º 7
0
def defaultimage(filename, width=None, height=None, kind='direct',
                                        mask="auto", lazy=1, srcinfo=None):
    ''' We have multiple image backends, including the stock reportlab one.
        This wrapper around the reportlab one allows us to pass the client
        RstToPdf object and the uri into all our backends, which they can
        use or not as necessary.
    '''
    return Image(filename, width, height, kind, mask, lazy)
Ejemplo n.º 8
0
def myFirstPage(canvas, doc):
    canvas.saveState()
    canvas.setFont('Helvetica-Bold', 20)
    canvas.drawCentredString(PAGE_WIDTH / 2.0, PAGE_HEIGHT - 108, Title)
    canvas.drawCentredString(PAGE_WIDTH / 2.0, PAGE_HEIGHT - 130, Date)
    im = Image("lucicoin.png", width=2 * inch, height=2 * inch)
    im.hAlign = 'LEFT'
    canvas.setFont('Helvetica', 9)
    canvas.drawString(inch, 0.75 * inch, "First Page / %s" % pageinfo)
    canvas.restoreState()
Ejemplo n.º 9
0
def create_user_info_document(output_file, teacher_list):
    logger.debug('Creating user info document...')
    subject_paragraph_style = ParagraphStyle(name='Normal',
                                             fontSize=12,
                                             leading=20,
                                             fontName='Times-Bold',
                                             spaceAfter=0.75 * cm)
    main_paragraph_style = ParagraphStyle(name='Normal',
                                          fontSize=11,
                                          leading=18,
                                          fontName='Times-Roman',
                                          spaceAfter=0.25 * cm,
                                          hyphenationLang='de_DE',
                                          embeddedHyphenation=1,
                                          uriWasteReduce=0.3)
    data_paragraph_style = ParagraphStyle(name='Normal',
                                          fontSize=11,
                                          fontName='Courier',
                                          spaceAfter=0.5 * cm,
                                          alignment=TA_CENTER)
    # prepare data for document
    title = 'Benutzerdaten'
    author = 'bbst - BBS Teacher Management'
    logo = Image('logo.png',
                 width=PAGE_WIDTH - 2 * BORDER_HORIZONTAL,
                 height=5.2445 * cm,
                 hAlign='CENTER')
    info_text_greeting = 'Liebe Kollegin, lieber Kollege,<br/>ihre Benutzerdaten lauten wie folgt:'
    info_text_paragraphs = [
        """Diese Zugangsdaten erlauben die Rechnernutzung in allen Räumen mit dem Logodidact-System.
    Außerdem kann es zum Zugriff auf den Stundenplan über WebUntis und die Lernplattform Moodle genutzt werden.""",
        """In Logodidact, Moodle und WebUntis lässt sich das Passwort ändern. Allerdings gilt jede Änderung nur für
    das jeweilige System! Sollten Sie ihr Passwort vergessen haben, besteht bei Moodle und Webuntis die
    Möglichkeit, sich ein neues Passwort per Mail zusenden zu lassen.""",
        """Weitere Informationen finden Sie im Moodle-Kurs unter
    <a color="blue" href="https://moodle.nibis.de/bbs_osb/course/view.php?id=7">https://moodle.nibis.de/bbs_osb/course/view.php?id=7</a>.
    Bei allen weiteren Fragen können Sie sich gerne bei mir melden.""",
        """<br/>Viele Grüße<br/>&nbsp;&nbsp;&nbsp;&nbsp;Christian Wichmann<br/>&nbsp;&nbsp;&nbsp;&nbsp;[email protected]"""
    ]
    # building document
    doc = SimpleDocTemplate(output_file, author=author, title=title)
    story = []
    for t in teacher_list:
        user_data = '{}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{}'.format(
            t.username.lower(), t.password)
        story.append(logo)
        story.append(Spacer(1, 1.75 * cm))
        story.append(
            Paragraph('<b>{}</b>'.format(title), subject_paragraph_style))
        story.append(Paragraph(info_text_greeting, main_paragraph_style))
        story.append(Paragraph(user_data, data_paragraph_style))
        for p in info_text_paragraphs:
            story.append(Paragraph(p, main_paragraph_style))
        story.append(PageBreak())
    doc.build(story, onFirstPage=build_footer, onLaterPages=build_footer)
Ejemplo n.º 10
0
    def myLaterPages(self, canvas, doc):
        Image('PhEDEx-banner.png', width=A4[0],
              height=75).drawOn(canvas, 0, (A4[1] - 75))
        self.allPages(canvas, doc)

        style = self.getStyle()
        date = self.getDate()
        P = Paragraph("%s PhEDEx Report" % self.site, style["ReportTitle"])
        size = P.wrap(A4[0], 200)
        P.wrapOn(canvas, A4[0], size[1])
        top = 10 + size[1]
        P.drawOn(canvas, 0, A4[1] - top)
Ejemplo n.º 11
0
 def draw(self):
     canvas = self.canv
     img = Image(self.barcode)
     width, height = img.wrapOn(canvas, 0, 0)
     width = width * 72. / 300
     height = height * 72. / 300
     canvas.drawImage(
         self.barcode,
         self.x * mm,
         (self.y * mm * -1) - height,
         width,
         height,
     )
Ejemplo n.º 12
0
    def add_image(self, src, width, height, align=CENTER, caption=None):

        if src.split(".")[-1] in ["png", "PNG"]:
            try:
                f = open(src, 'rb')
                data = StringIO(f.read())
            except:
                return
            else:
                img = Image(data, width, height)
                f.close()
        else:
            img = Image(src, width, height)

        img.hAlign = align
        if caption:
            caption_p = Paragraph(caption, self.theme.paragraph_centered)
            image_table = Table([[img], [caption_p]], width)
            image_table.setStyle(
                TableStyle([('ALIGN', (-1, -1), (-1, -1), 'CENTER')]))
            self.add(image_table)
        else:
            self.add(img)
Ejemplo n.º 13
0
 def insert_image(self,
                  path: str,
                  x: int = 100,
                  y: int = 200,
                  width: int = None,
                  height: int = None):
     """
     This function inserts image in pdf-file\n
     size of page is 595.27,841.89\n
     :param path: path to image
     :param x, y: coordinates of left-bottom corner of image
     :param width, height: sizes of image
     """
     image = Image(path, width, height)
     image.drawOn(self.file, x, y)
Ejemplo n.º 14
0
    def allPages(self, canvas, doc):
        #Background images
        Image('phedex_outline.png', width=A4[0] - 50,
              height=A4[0] - 50).drawOn(canvas, 25, (A4[1] / 2) - (A4[0] / 2))

        #Footer text
        style = self.getStyle()
        date = self.getDate()
        P = Paragraph(
            "%s PhEDEx Report for week beginning %s  - Page %d" %
            (self.site, date, doc.page), style["Footer"])
        size = P.wrap(A4[0], 200)
        P.wrapOn(canvas, A4[0] - 20, size[1])
        top = 10 + size[1]
        P.drawOn(canvas, 0, top)
Ejemplo n.º 15
0
 def doImport(self):
     style = self.getStyle()
     text = '''Import transfer rates and quality for %s. 
     Maximum daily rate is 237MB/s, minimum rate is 100MB/s, 
     average 169/MB/s. Average quality for the week is 30 percent.''' % self.site
     importPara = [
         Spacer(inch * .25, inch * .25),
         Paragraph('Data Import', style['SectionTitle']),
         Paragraph(text, style=style["Normal_just"])
     ]
     png = 'Picture 1.png'
     importImg = ImageAndFlowables(Image(png, width=340, height=240),
                                   importPara,
                                   imageLeftPadding=0,
                                   imageRightPadding=20,
                                   imageSide='left')
     return KeepTogether([importImg, Spacer(inch * .125, inch * .125)])
Ejemplo n.º 16
0
def defaultimage(
    filename,
    width=None,
    height=None,
    kind='direct',
    mask='auto',
    lazy=1,
    srcinfo=None,
):
    """Get default image backend.

    We have multiple image backends, including the stock ReportLab one.  This
    wrapper around the ReportLab one allows us to pass the client ``RstToPdf``
    object and the URI into all our backends, which they can use (or not) as
    necessary.
    """
    return Image(filename, width, height, kind, mask, lazy)
Ejemplo n.º 17
0
 def resize_images(self, story):
     # replace images with resized ones fitting into the available width
     W, H = (self.width - self.lm -
             self.rm), self.height - self.tm - self.bm
     for i, el in enumerate(story):
         if el.__class__ == Image:
             img = PIL.Image.open(el.filename)
             h = W / img.size[0] * img.size[1]
             img = Image(el.filename,
                         width=w,
                         height=h,
                         kind='direct',
                         mask="auto",
                         lazy=1)
             story[i] = img
         elif type(el) == str:
             story[i] = Paragraph(el, bt)  # Spacer(0, 0)
Ejemplo n.º 18
0
 def AddTableRow(self, element):
     cells = []
     color = self._ConvertColor(element, "background")
     if color is not None:
         start = (0, len(self.tableRows))
         stop = (-1, len(self.tableRows))
         self.tableCommands.append(("BACKGROUND", start, stop, color))
     for cell in element:
         if cell.tag == "td":
             rowSpan = int(cell.get("rowspan", 1))
             colSpan = int(cell.get("colspan", 1))
             if rowSpan > 1 or colSpan > 1:
                 start = (len(cells), len(self.tableRows))
                 stop = (len(cells) + colSpan - 1,
                         len(self.tableRows) + rowSpan - 1)
                 self.tableCommands.append(("SPAN", start, stop))
             color = self._ConvertColor(cell, "background")
             if color is not None:
                 start = stop = (len(cells), len(self.tableRows))
                 self.tableCommands.append(
                     ("BACKGROUND", start, stop, color))
             contents = []
             for child in cell:
                 if child.tag == "para":
                     styleName = child.get("style", "default")
                     rotated = self._ConvertNumber(child, "rotate")
                     style = self.paragraphStyles[styleName]
                     child.attrib.clear()
                     text = cElementTree.tostring(child)
                     cls = RotatedParagraph if rotated else Paragraph
                     para = cls(text, style)
                     contents.append(para)
                 elif child.tag == "img":
                     fileName = child.get("src", "unknown.png")
                     width = self._ConvertNumber(child, "width")
                     height = self._ConvertNumber(child, "height")
                     img = Image(fileName, width, height)
                     contents.append(img)
             if not contents:
                 contents = cell.text and cell.text.strip()
             cells.append(contents)
     height = self._ConvertNumber(element, "height")
     self.tableRows.append(cells)
     self.tableRowHeights.append(height)
Ejemplo n.º 19
0
def __plot_common_(width, method, p=0.48):
    fig = plt.figure(figsize=(15, 15*p))
    plt.grid(axis="y", linestyle="-", color="#637a8f", linewidth=2)

    method()

    # plt.xticks(fontsize=12)
    # plt.yticks(fontsize=12)

    ax = plt.gca()
    ax.set_axisbelow(True)
    ax.spines['top'].set_color("none")
    ax.spines['right'].set_color("none")
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')

    img_data = io.BytesIO()
    fig.savefig(img_data, format='png')
    img_data.seek(0)
    im = Image(img_data, width=width, height=width * p)
    return [im, Spacer(6, 20)]
def myFirstPage(canvas, doc):
    canvas.saveState()
    canvas.setFont('Times-Bold', 16)
    canvas.drawCentredString(PAGE_WIDTH / 2.0, PAGE_HEIGHT - 108, title)
    canvas.setFont('Times-Roman', 9)
    canvas.drawString(inch, 0.75 * inch, "Page %d - %s" % (doc.page, title))

    frame_width = PAGE_WIDTH - 200
    hr = HRFlowable()
    space = Spacer(frame_width, 20)
    style = styles["Normal"]
    qr_info = """<para rightIndent=10 leftIndent=20 alignment=right>This document is signed with the QR code shown on the right. Validate it using a Barcode Scanner."""
    par = Paragraph(qr_info, style)
    im = Image("qrcode.png", 101, 101)
    pandi = ParagraphAndImage(par, im, xpad=3, ypad=30, side='right')

    frame = Frame(100, 0, frame_width, 200, showBoundary=1)
    frame.add(hr, canvas)
    frame.add(space, canvas)
    frame.add(pandi, canvas)
    canvas.restoreState()
Ejemplo n.º 21
0
def get_doc_elements(queryset, med_p=False):
    elements = []
    summary_data = []
    already_added_images = []
    for qs in queryset.order_by("invoice_number"):
        dd = [
            qs.prestations.all().order_by("date", "carecode__name")[i:i + 20]
            for i in range(0, len(qs.prestations.all()), 20)
        ]
        for _prestations in dd:
            _inv = qs.invoice_number + (
                ("" + str(dd.index(_prestations) + 1) +
                 qs.invoice_date.strftime('%m%Y')) if len(dd) > 1 else "")
            _result = _build_invoices(_prestations, _inv, qs.invoice_date,
                                      qs.accident_id, qs.accident_date)

            elements.extend(_result["elements"])
            summary_data.append(
                (_result["invoice_number"], _result["patient_name"],
                 _result["invoice_amount"]))
            elements.append(PageBreak())
            if med_p and qs.medical_prescription and bool(qs.medical_prescription.file) \
                    and qs.medical_prescription.file.file.name not in already_added_images:
                elements.append(
                    Image(qs.medical_prescription.file,
                          width=469.88,
                          height=773.19))
                elements.append(PageBreak())
                already_added_images.append(
                    qs.medical_prescription.file.file.name)
    recap_data = _build_recap(summary_data)
    elements.extend(recap_data[0])
    elements.append(PageBreak())
    elements.extend(_build_final_page(recap_data[1], recap_data[2]))

    return elements
Ejemplo n.º 22
0
def generate_pdf(file):
    with open(file, 'r', encoding='utf-8') as file:
        data = file.read().replace('\n', '<br/>') \
            .replace('Juliet: <Media weggelaten> Neutral', 'Juliet: ' + 1 * "<br/>" + 11 * '<br/>' +
                     '<img src= "img_resized/neutral_juliet.jpg"/>' + 1 * '<br/>') \
            .replace('Juliet: <Media weggelaten> Positive', 'Juliet: ' + 1 * "<br/>" + 11 * '<br/>' +
                     '<img src= "img_resized/happy_juliet.jpg"/>' + 1 * '<br/>') \
            .replace('Juliet: <Media weggelaten> Negative', 'Juliet: ' + 1 * "<br/>" + 11 * '<br/>' +
                     '<img src= "img_resized/angry_juliet.jpg"/>' + 1 * '<br/>') \
            .replace('Romeo: <Media weggelaten> Neutral', 'Romeo: ' + 1 * "<br/>" + 11 * '<br/>' +
                     '<img src= "img_resized/neutral_romeo.jpg"/>' + 1 * '<br/>') \
            .replace('Romeo: <Media weggelaten> Positive', 'Romeo: ' + 1 * "<br/>" + 11 * '<br/>' +
                     '<img src= "img_resized/happy_romeo.jpg"/>' + 1 * '<br/>') \
            .replace('Romeo: <Media weggelaten> Negative', 'Romeo: ' + 1 * "<br/>" + 11 * '<br/>' +
                     '<img src= "img_resized/angry_romeo.jpg"/>' + 1 * '<br/>')

    story = [
        DocAssign("currentFrame", "doc.frame.id"),
        DocAssign("currentPageTemplate", "doc.pageTemplate.id"),
        DocAssign("aW", "availableWidth"),
        DocAssign("aH", "availableHeight"),
        DocAssign("aWH", "availableWidth,availableHeight"),
        Paragraph("<b>Romeo and Juliet</b>" + 15 * '<br/>', title),
        Image('img/romeo_juliet.jpg', width=4 * inch, height=5 * inch),
        PageBreak(),
        Paragraph("<b>Introduction</b>", header),
        Paragraph(
            2 * '<br/>' +
            "<i>A 2019 interpretation of the famous love story in the form of a WhatsApp dialogue. Made for NaNoGenMo.</i>",
            normal),
        PageBreak(),
        Paragraph(data, normal)
    ]

    doc = SimpleDocTemplate("romeo_and_juliet.pdf")
    doc.build(story)
Ejemplo n.º 23
0
def pdf(group, bill):
    """PDF version of bill"""

    width, height = A4
    margin = 1 * cm
    heading = 2 * cm

    logo_height = 1.5 * cm

    font_name = 'Times-Roman'
    font_size = 16

    filename = '%s-%s-%s-%s' % (date.today(), group, _('bill'), bill.id)

    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment; filename=%s.pdf' % (
        slugify(filename))

    show_logo = bool(group.logo and group.logo.storage.exists(group.logo.path))

    if show_logo:
        ratio = group.logo.width / group.logo.height
        logo = Image(group.logo.path,
                     width=logo_height * ratio,
                     height=logo_height)

    def draw_header(canvas, doc):
        if show_logo:
            logo.drawOn(canvas, width / 2 - 1 * margin - logo_height * ratio,
                        height - margin - logo_height)

        canvas.setFont(font_name, font_size)
        canvas.drawString(margin, height - margin - font_size,
                          _('Bill #%d') % (bill.id))
        canvas.setFont(font_name, font_size - 4)
        canvas.drawString(
            margin, height - margin - 2 * font_size,
            bill.created.strftime(_('%Y-%m-%d %H:%M').encode('utf-8')))

    frames = [
        Frame(0,
              0,
              width / 2,
              height - heading,
              leftPadding=margin,
              bottomPadding=margin,
              rightPadding=margin / 2,
              topPadding=margin),
        Frame(width / 2,
              0,
              width / 2,
              height,
              leftPadding=margin / 2,
              bottomPadding=margin,
              rightPadding=margin,
              topPadding=margin),
    ]

    templates = [PageTemplate(frames=frames, onPage=draw_header)]

    doc = BaseDocTemplate(response, pagesize=(width, height))
    doc.addPageTemplates(templates)

    data = [[_('Description'), _('Amount')]]
    total = 0

    for line in bill.billingline_set.all():
        data.append([line.description, '%.2f' % line.amount])
        total += line.amount

    data.append(['', '%.2f' % total])

    table = Table(data, colWidths=[doc.width * 0.4, doc.width * 0.15])
    table.setStyle(table_style)
    table.hAlign = 'LEFT'

    parts = []
    for line in bill.description.split('\n'):
        parts.append(Paragraph(escape(line), styles['Normal']))
    parts.append(Spacer(0.2 * cm, 0.2 * cm))
    parts.append(KeepTogether(table))

    doc.build(parts)

    return response
Ejemplo n.º 24
0
    def Impression(self, listeActivites, listePeriodes):
        # Création du PDF
        self.taille_page = A4
        self.orientation = "PORTRAIT"
        if self.orientation == "PORTRAIT" :
            self.hauteur_page = self.taille_page[1]
            self.largeur_page = self.taille_page[0]
        else:
            self.hauteur_page = self.taille_page[0]
            self.largeur_page = self.taille_page[1]
        
        # Création des conditions pour les requêtes SQL
        conditionsPeriodes = GetSQLdates(listePeriodes)
        
        if len(listeActivites) == 0 : conditionActivites = "()"
        elif len(listeActivites) == 1 : conditionActivites = "(%d)" % listeActivites[0]
        else : conditionActivites = str(tuple(listeActivites))
                                    
        # Récupération des individus grâce à leurs consommations
        self.EcritStatusBar(_(u"Recherche des individus..."))
        DB = GestionDB.DB() 
        req = """SELECT individus.IDindividu, IDcivilite, nom, prenom, date_naiss
        FROM consommations 
        LEFT JOIN individus ON individus.IDindividu = consommations.IDindividu
        WHERE etat IN ("reservation", "present")
        AND IDactivite IN %s AND %s
        GROUP BY individus.IDindividu
        ORDER BY nom, prenom
        ;""" % (conditionActivites, conditionsPeriodes)
        DB.ExecuterReq(req)
        listeIndividus = DB.ResultatReq()
        DB.Close() 
        if len(listeIndividus) == 0 :
            dlg = wx.MessageDialog(self, _(u"Aucun individu n'a été trouvé avec les paramètres spécifiés !"), _(u"Erreur"), wx.OK | wx.ICON_EXCLAMATION)
            dlg.ShowModal()
            dlg.Destroy()
            self.EcritStatusBar(u"")
            return

        dictIndividus = {}
        listeIDindividus = []
        
        dictAnniversaires = {} 
        
        self.EcritStatusBar(_(u"Recherche des dates de naissance..."))
        for IDindividu, IDcivilite, nom, prenom, date_naiss in listeIndividus :
            if date_naiss != None : 
                date_naiss = DateEngEnDateDD(date_naiss)
                age = GetAge(date_naiss)
                jour = date_naiss.day
                mois = date_naiss.month
                
                # Mémorisation de l'individu
                dictIndividus[IDindividu] = { 
                    "IDcivilite" : IDcivilite, "nom" : nom, "prenom" : prenom, 
                    "age" : age, "date_naiss" : date_naiss,
                    }
                
                # Mémorisation du IDindividu
                if dictAnniversaires.has_key(mois) == False : 
                    dictAnniversaires[mois] = {} 
                if dictAnniversaires[mois].has_key(jour) == False : 
                    dictAnniversaires[mois][jour] = []
                dictAnniversaires[mois][jour].append(IDindividu)
                
                if IDindividu not in listeIDindividus :
                    listeIDindividus.append(IDindividu) 
                
        # Récupération des photos individuelles
        dictPhotos = {}
        taillePhoto = 128
        if self.ctrl_photos.GetSelection() == 0 : tailleImageFinal = 16
        if self.ctrl_photos.GetSelection() == 1 : tailleImageFinal = 32
        if self.ctrl_photos.GetSelection() == 2 : tailleImageFinal = 64
        if self.check_photos.GetValue() == True :
            index = 0
            for IDindividu in listeIDindividus :
                self.EcritStatusBar(_(u"Recherche des photos... %d/%d") % (index, len(listeIDindividus)))
                IDcivilite = dictIndividus[IDindividu]["IDcivilite"]
                nomFichier = Chemins.GetStaticPath("Images/128x128/%s" % DICT_CIVILITES[IDcivilite]["nomImage"])
                IDphoto, bmp = CTRL_Photo.GetPhoto(IDindividu=IDindividu, nomFichier=nomFichier, taillePhoto=(taillePhoto, taillePhoto), qualite=100)
                
                # Création de la photo dans le répertoire Temp
                nomFichier = UTILS_Fichiers.GetRepTemp(fichier="photoTmp%d.jpg" % IDindividu)
                bmp.SaveFile(nomFichier, type=wx.BITMAP_TYPE_JPEG)
                img = Image(nomFichier, width=tailleImageFinal, height=tailleImageFinal)
                dictPhotos[IDindividu] = img
                
                index += 1
            
        # ---------------- Création du PDF -------------------
        self.EcritStatusBar(_(u"Création du PDF...")) 
        
        # Initialisation du PDF
        nomDoc = FonctionsPerso.GenerationNomDoc("ANNIVERSAIRES", "pdf")
        if sys.platform.startswith("win") : nomDoc = nomDoc.replace("/", "\\")
        doc = BaseDocTemplate(nomDoc, pagesize=(self.largeur_page, self.hauteur_page), topMargin=30, bottomMargin=30, showBoundary=False)
        doc.addPageTemplates(MyPageTemplate(pageSize=(self.largeur_page, self.hauteur_page)))
        story = []
                        
        # Mois
        listeMois = dictAnniversaires.keys()
        listeMois.sort() 
        for numMois in listeMois :
            
            # Mémorise le numéro de mois pour le titre de la page
            nomMois = LISTE_NOMS_MOIS[numMois-1]
            story.append(DocAssign("numMois", numMois))

            # Jours
            dictJours = dictAnniversaires[numMois]
            listeJours = dictJours.keys() 
            listeJours.sort() 
            for numJour in listeJours :                                
                # Initialisation du tableau
                dataTableau = []
                largeursColonnes = []
                                    
                # Recherche des entêtes de colonnes :
                if self.check_photos.GetValue() == True :
                    largeursColonnes.append(tailleImageFinal+6)
                
                # Colonne nom de l'individu
                largeursColonnes.append(LARGEUR_COLONNE-sum(largeursColonnes))
                
                # Label numéro de jour
                ligne = []
                ligne.append(str(numJour))
                if self.check_photos.GetValue() == True :
                    ligne.append(u"")
                dataTableau.append(ligne)
                
                # Individus
                listeIndividus = dictAnniversaires[numMois][numJour]
                
                for IDindividu in listeIndividus :
                    ligne = []
                    
                    # Photo
                    if self.check_photos.GetValue() == True and IDindividu in dictPhotos :
                        img = dictPhotos[IDindividu]
                        ligne.append(img)
                    
                    # Nom
                    nom = dictIndividus[IDindividu]["nom"]
                    prenom = dictIndividus[IDindividu]["prenom"]
                    ligne.append(u"%s %s" % (nom, prenom))
                    
                    # Ajout de la ligne individuelle dans le tableau
                    dataTableau.append(ligne)
             
                couleurFondJour = (0.8, 0.8, 1) # Vert -> (0.5, 1, 0.2)
                couleurFondTableau = (1, 1, 1)
                
                style = TableStyle([
                        ('VALIGN', (0,0), (-1,-1), 'MIDDLE'), # Centre verticalement toutes les cases
                        ('BACKGROUND', (0,0), (-1,-1), couleurFondTableau), # Donne la couleur de fond du titre de groupe
                        
                        ('FONT',(0,0),(-1,-1), "Helvetica", 7), # Donne la police de caract. + taille de police 
                        ('GRID', (0,0), (-1,-1), 0.25, colors.black), # Crée la bordure noire pour tout le tableau
                        ('ALIGN', (0,1), (-1,-1), 'CENTRE'), # Centre les cases
                        
                        ('SPAN',(0,0),(-1,0)), # Fusionne les lignes du haut pour faire le titre du groupe
                        ('FONT',(0,0),(0,0), "Helvetica-Bold", 10), # Donne la police de caract. + taille de police du titre de groupe
                        ('BACKGROUND', (0,0), (-1,0), couleurFondJour), # Donne la couleur de fond du titre de groupe
                        
                        ])
                    
                # Création du tableau
                tableau = Table(dataTableau, largeursColonnes)
                tableau.setStyle(style)
                story.append(tableau)
                story.append(Spacer(0, 10))
                    
            # Saut de page après un mois
            story.append(PageBreak())
            
        # Enregistrement du PDF
        doc.build(story)
        
        # Affichage du PDF
        FonctionsPerso.LanceFichierExterne(nomDoc)
        
        self.EcritStatusBar(u"") 
Ejemplo n.º 25
0
def old_tables_test():
    from reportlab.lib.units import inch, cm
    from reportlab.platypus.flowables import Image, PageBreak, Spacer, XBox
    from reportlab.platypus.paragraph import Paragraph
    from reportlab.platypus.xpreformatted import XPreformatted
    from reportlab.platypus.flowables import Preformatted
    from reportlab.platypus.doctemplate import SimpleDocTemplate
    from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
    from reportlab.platypus.tables import GRID_STYLE, BOX_STYLE, LABELED_GRID_STYLE, COLORED_GRID_STYLE, LIST_STYLE, LongTable
    rowheights = (24, 16, 16, 16, 16)
    rowheights2 = (24, 16, 16, 16, 30)
    colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32)
    data = (
        ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
        ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
        ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
        ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
        ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843')
        )
    data2 = (
        ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
        ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
        ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
        ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
        ('Hats\nLarge', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843')
        )
    lst = []
    lst.append(Paragraph("Tables", styleSheet['Heading1']))
    lst.append(Paragraph(__doc__, styleSheet['BodyText']))
    lst.append(Paragraph("The Tables (shown in different styles below) were created using the following code:", styleSheet['BodyText']))
    lst.append(Preformatted("""
    colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32)
    rowheights = (24, 16, 16, 16, 16)
    data = (
        ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun',
           'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
        ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
        ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
        ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
        ('Hats', 893, 912, '1,212', 643, 789, 159,
             888, '1,298', 832, 453, '1,344','2,843')
        )
    t = Table(data, colwidths, rowheights)
    """, styleSheet['Code'], dedent=4))
    lst.append(Paragraph("""
    You can then give the Table a TableStyle object to control its format. The first TableStyle used was
    created as follows:
    """, styleSheet['BodyText']))
    lst.append(Preformatted("""
GRID_STYLE = TableStyle(
    [('GRID', (0,0), (-1,-1), 0.25, colors.black),
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
    )
    """, styleSheet['Code']))
    lst.append(Paragraph("""
    TableStyles are created by passing in a list of commands. There are two types of commands - line commands
    and cell formatting commands. In all cases, the first three elements of a command are the command name,
    the starting cell and the ending cell.
    """, styleSheet['BodyText']))
    lst.append(Paragraph("""
    Line commands always follow this with the weight and color of the desired lines. Colors can be names,
    or they can be specified as a (R,G,B) tuple, where R, G and B are floats and (0,0,0) is black. The line
    command names are: GRID, BOX, OUTLINE, INNERGRID, LINEBELOW, LINEABOVE, LINEBEFORE
    and LINEAFTER. BOX and OUTLINE are equivalent, and GRID is the equivalent of applying both BOX and
    INNERGRID.
    """, styleSheet['BodyText']))
    lst.append(Paragraph("""
    Cell formatting commands are:
    """, styleSheet['BodyText']))
    lst.append(Paragraph("""
    FONT - takes fontname, fontsize and (optional) leading.
    """, styleSheet['Definition']))
    lst.append(Paragraph("""
    TEXTCOLOR - takes a color name or (R,G,B) tuple.
    """, styleSheet['Definition']))
    lst.append(Paragraph("""
    ALIGNMENT (or ALIGN) - takes one of LEFT, RIGHT, CENTRE (or CENTER) or DECIMAL.
    """, styleSheet['Definition']))
    lst.append(Paragraph("""
    LEFTPADDING - defaults to 6.
    """, styleSheet['Definition']))
    lst.append(Paragraph("""
    RIGHTPADDING - defaults to 6.
    """, styleSheet['Definition']))
    lst.append(Paragraph("""
    BOTTOMPADDING - defaults to 3.
    """, styleSheet['Definition']))
    lst.append(Paragraph("""
    A tablestyle is applied to a table by calling Table.setStyle(tablestyle).
    """, styleSheet['BodyText']))
    t = Table(data, colwidths, rowheights)
    t.setStyle(GRID_STYLE)
    lst.append(PageBreak())
    lst.append(Paragraph("This is GRID_STYLE\n", styleSheet['BodyText']))
    lst.append(t)

    t = Table(data, colwidths, rowheights)
    t.setStyle(BOX_STYLE)
    lst.append(Paragraph("This is BOX_STYLE\n", styleSheet['BodyText']))
    lst.append(t)
    lst.append(Paragraph("""
    It was created as follows:
    """, styleSheet['BodyText']))
    lst.append(Preformatted("""
BOX_STYLE = TableStyle(
    [('BOX', (0,0), (-1,-1), 0.50, colors.black),
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
    )
    """, styleSheet['Code']))

    t = Table(data, colwidths, rowheights)
    t.setStyle(LABELED_GRID_STYLE)
    lst.append(Paragraph("This is LABELED_GRID_STYLE\n", styleSheet['BodyText']))
    lst.append(t)
    t = Table(data2, colwidths, rowheights2)
    t.setStyle(LABELED_GRID_STYLE)
    lst.append(Paragraph("This is LABELED_GRID_STYLE ILLUSTRATES EXPLICIT LINE SPLITTING WITH NEWLINE (different heights and data)\n", styleSheet['BodyText']))
    lst.append(t)
    lst.append(Paragraph("""
    It was created as follows:
    """, styleSheet['BodyText']))
    lst.append(Preformatted("""
LABELED_GRID_STYLE = TableStyle(
    [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
     ('BOX', (0,0), (-1,-1), 2, colors.black),
     ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
     ('LINEAFTER', (0,0), (0,-1), 2, colors.black),
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
    )
    """, styleSheet['Code']))
    lst.append(PageBreak())

    t = Table(data, colwidths, rowheights)
    t.setStyle(COLORED_GRID_STYLE)
    lst.append(Paragraph("This is COLORED_GRID_STYLE\n", styleSheet['BodyText']))
    lst.append(t)
    lst.append(Paragraph("""
    It was created as follows:
    """, styleSheet['BodyText']))
    lst.append(Preformatted("""
COLORED_GRID_STYLE = TableStyle(
    [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
     ('BOX', (0,0), (-1,-1), 2, colors.red),
     ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
     ('LINEAFTER', (0,0), (0,-1), 2, colors.black),
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
    )
    """, styleSheet['Code']))

    t = Table(data, colwidths, rowheights)
    t.setStyle(LIST_STYLE)
    lst.append(Paragraph("This is LIST_STYLE\n", styleSheet['BodyText']))
    lst.append(t)
    lst.append(Paragraph("""
    It was created as follows:
    """, styleSheet['BodyText']))
    lst.append(Preformatted("""
LIST_STYLE = TableStyle(
    [('LINEABOVE', (0,0), (-1,0), 2, colors.green),
     ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
     ('LINEBELOW', (0,-1), (-1,-1), 2, colors.green),
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
    )
    """, styleSheet['Code']))

    t = Table(data, colwidths, rowheights)
    ts = TableStyle(
    [('LINEABOVE', (0,0), (-1,0), 2, colors.green),
     ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
     ('LINEBELOW', (0,-1), (-1,-1), 3, colors.green,'butt'),
     ('LINEBELOW', (0,-1), (-1,-1), 1, colors.white,'butt'),
     ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
     ('TEXTCOLOR', (0,1), (0,-1), colors.red),
     ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))]
    )
    t.setStyle(ts)
    lst.append(Paragraph("This is a custom style\n", styleSheet['BodyText']))
    lst.append(t)
    lst.append(Paragraph("""
    It was created as follows:
    """, styleSheet['BodyText']))
    lst.append(Preformatted("""
   ts = TableStyle(
    [('LINEABOVE', (0,0), (-1,0), 2, colors.green),
     ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
     ('LINEBELOW', (0,-1), (-1,-1), 3, colors.green,'butt'),
     ('LINEBELOW', (0,-1), (-1,-1), 1, colors.white,'butt'),
     ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
     ('TEXTCOLOR', (0,1), (0,-1), colors.red),
     ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))]
    )
    """, styleSheet['Code']))
    data = (
        ('', 'Jan\nCold', 'Feb\n', 'Mar\n','Apr\n','May\n', 'Jun\nHot', 'Jul\n', 'Aug\nThunder', 'Sep\n', 'Oct\n', 'Nov\n', 'Dec\n'),
        ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
        ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
        ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
        ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843')
        )
    c = list(colwidths)
    c[0] = None
    c[8] = None
    t = Table(data, c, [None]+list(rowheights[1:]))
    t.setStyle(LIST_STYLE)
    lst.append(Paragraph("""
        This is a LIST_STYLE table with the first rowheight set to None ie automatic.
        The top row cells are split at a newline '\\n' character. The first and August
        column widths were also set to None.
    """, styleSheet['BodyText']))
    lst.append(t)

    lst.append(Paragraph("""
        This demonstrates a number of features useful in financial statements. The first is decimal alignment;
        with ALIGN=DECIMAL the numbers align on the points; and the points are aligned based on
        the RIGHTPADDING, which is usually 3 points so you should set it higher.  The second is multiple lines;
        one can specify double or triple lines and control the separation if desired. Finally, the coloured
        negative numbers were (we regret to say) done in the style; we don't have a way to conditionally
        format numbers based on value yet.
    """, styleSheet['BodyText']))


    t = Table([['Corporate Assets','Amount'],
               ['Fixed Assets','1,234,567.89'],
               ['Company Vehicle','1,234.8901'],
               ['Petty Cash','42'],
               [u'Intellectual Property\u00ae','(42,078,231.56)'],
               ['Overdraft','(12,345)'],
               ['Boardroom Flat Screen','60 inches'],
               ['Net Position','Deep Sh*t.Really']
               ],
              [144,72])

    ts = TableStyle(
        [#first the top row
         ('ALIGN', (1,1), (-1,-1), 'CENTER'),
         ('LINEABOVE', (0,0), (-1,0), 1, colors.purple),
         ('LINEBELOW', (0,0), (-1,0), 1, colors.purple),
         ('FONT', (0,0), (-1,0), 'Times-Bold'),

        #bottom row has a line above, and two lines below
         ('LINEABOVE', (0,-1), (-1,-1), 1, colors.purple),  #last 2 are count, sep
         ('LINEBELOW', (0,-1), (-1,-1), 0.5, colors.purple, 1, None, None, 4,1),
         ('LINEBELOW', (0,-1), (-1,-1), 1, colors.red),
         ('FONT', (0,-1), (-1,-1), 'Times-Bold'),

        #numbers column
         ('ALIGN', (1,1), (-1,-1), 'DECIMAL'),
         ('RIGHTPADDING', (1,1), (-1,-1), 36),
         ('TEXTCOLOR', (1,4), (1,4), colors.red),

        #red cell
        ]
        )

    t.setStyle(ts)
    lst.append(t)
    lst.append(Spacer(36,36))
    lst.append(Paragraph("""
        The red numbers should be aligned LEFT &amp; BOTTOM, the blue RIGHT &amp; TOP
        and the green CENTER &amp; MIDDLE.
    """, styleSheet['BodyText']))
    XY  =   [['X00y', 'X01y', 'X02y', 'X03y', 'X04y'],
            ['X10y', 'X11y', 'X12y', 'X13y', 'X14y'],
            ['X20y', 'X21y', 'X22y', 'X23y', 'X24y'],
            ['X30y', 'X31y', 'X32y', 'X33y', 'X34y']]
    t=Table(XY, 5*[0.6*inch], 4*[0.6*inch])
    t.setStyle([('ALIGN',(1,1),(-2,-2),'LEFT'),
                ('TEXTCOLOR',(1,1),(-2,-2),colors.red),

                ('VALIGN',(0,0),(1,-1),'TOP'),
                ('ALIGN',(0,0),(1,-1),'RIGHT'),
                ('TEXTCOLOR',(0,0),(1,-1),colors.blue),

                ('ALIGN',(0,-1),(-1,-1),'CENTER'),
                ('VALIGN',(0,-1),(-1,-1),'MIDDLE'),
                ('TEXTCOLOR',(0,-1),(-1,-1),colors.green),
                ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
                ('BOX', (0,0), (-1,-1), 0.25, colors.black),
                ])
    lst.append(t)
    data = [('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')]
    t = Table(data)
    t.setStyle([
            ('VALIGN',(0,0),(-1,-1),'TOP'),
            ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
            ('BOX', (0,0), (-1,-1), 0.25, colors.black),
            ])
    lst.append(t)
    t = Table([ ('Attribute', 'Synonyms'),
                ('alignment', 'align, alignment'),
                ('bulletColor', 'bulletcolor, bcolor'),
                ('bulletFontName', 'bfont, bulletfontname'),
                ('bulletFontSize', 'bfontsize, bulletfontsize'),
                ('bulletIndent', 'bindent, bulletindent'),
                ('firstLineIndent', 'findent, firstlineindent'),
                ('fontName', 'face, fontname, font'),
                ('fontSize', 'size, fontsize'),
                ('leading', 'leading'),
                ('leftIndent', 'leftindent, lindent'),
                ('rightIndent', 'rightindent, rindent'),
                ('spaceAfter', 'spaceafter, spacea'),
                ('spaceBefore', 'spacebefore, spaceb'),
                ('textColor', 'fg, textcolor, color')])
    t.repeatRows = 1
    t.setStyle([
                ('FONT',(0,0),(-1,1),'Times-Bold',10,12),
                ('FONT',(0,1),(-1,-1),'Courier',8,8),
                ('VALIGN',(0,0),(-1,-1),'MIDDLE'),
                ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
                ('BOX', (0,0), (-1,-1), 0.25, colors.black),
                ('BACKGROUND', (0, 0), (-1, 0), colors.green),
                ('BACKGROUND', (0, 1), (-1, -1), colors.pink),
                ('ALIGN', (0, 0), (-1, 0), 'CENTER'),
                ('ALIGN', (0, 1), (0, -1), 'LEFT'),
                ('ALIGN', (-1, 1), (-1, -1), 'RIGHT'),
                ('FONT', (0, 0), (-1, 0), 'Times-Bold', 12),
                ('ALIGN', (1, 1), (1, -1), 'CENTER'),
                ])
    lst.append(t)
    lst.append(Table(XY,
            style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 5,6),
                    ('GRID', (0,0), (-1,-1), 0.25, colors.blue),]))
    lst.append(Table(XY,
            style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 10,12),
                    ('GRID', (0,0), (-1,-1), 0.25, colors.black),]))
    lst.append(Table(XY,
            style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 20,24),
                    ('GRID', (0,0), (-1,-1), 0.25, colors.red),]))
    lst.append(PageBreak())
    data=  [['00', '01', '02', '03', '04'],
            ['10', '11', '12', '13', '14'],
            ['20', '21', '22', '23', '24'],
            ['30', '31', '32', '33', '34']]
    t=Table(data,style=[
                    ('GRID',(0,0),(-1,-1),0.5,colors.grey),
                    ('GRID',(1,1),(-2,-2),1,colors.green),
                    ('BOX',(0,0),(1,-1),2,colors.red),
                    ('BOX',(0,0),(-1,-1),2,colors.black),
                    ('LINEABOVE',(1,2),(-2,2),1,colors.blue),
                    ('LINEBEFORE',(2,1),(2,-2),1,colors.pink),
                    ('BACKGROUND', (0, 0), (0, 1), colors.pink),
                    ('BACKGROUND', (1, 1), (1, 2), colors.lavender),
                    ('BACKGROUND', (2, 2), (2, 3), colors.orange),
                    ('TEXTCOLOR',(0,-1),(-2,-1),colors.green),
                    ])
    lst.append(Paragraph("Illustrating splits: nosplit", styleSheet['BodyText']))
    lst.append(t)
    lst.append(Spacer(0,6))
    lst.append(Paragraph("Illustrating splits: split(4in,30)", styleSheet['BodyText']))
    for s in t.split(4*inch,30):
        lst.append(s)
        lst.append(Spacer(0,6))
    lst.append(Spacer(0,6))
    lst.append(Paragraph("Illustrating splits: split(4in,36)", styleSheet['BodyText']))
    for s in t.split(4*inch,36):
        lst.append(s)
        lst.append(Spacer(0,6))
    lst.append(Paragraph("Illustrating splits: split(4in,56)", styleSheet['BodyText']))
    lst.append(Spacer(0,6))
    for s in t.split(4*inch,56):
        lst.append(s)
        lst.append(Spacer(0,6))

    lst.append(Paragraph("Illustrating splits: repeated split(4in,30)", styleSheet['BodyText']))
    lst.append(Spacer(0,6))
    S = t.split(4*inch,30)
    s = S.pop(-1)
    S.extend(s.split(4*inch,30))
    s = S.pop(-1)
    S.extend(s.split(4*inch,30))

    for s in S:
        lst.append(s)
        lst.append(Spacer(0,6))

    lst.append(PageBreak())
    data=  [['00', '01', '02', '03', '04'],
            ['', '11', '12', '13', '14'],
            ['20', '21', '22', '23', '24'],
            ['30', '31', '', '33', '34']]
    sty=[
                    ('GRID',(0,0),(-1,-1),0.5,colors.grey),
                    ('GRID',(1,1),(-2,-2),1,colors.green),
                    ('BOX',(0,0),(1,-1),2,colors.red),
                    ('BOX',(0,0),(-1,-1),2,colors.black),
                    ('LINEABOVE',(1,2),(-2,2),1,colors.blue),
                    ('LINEBEFORE',(2,1),(2,-2),1,colors.pink),
                    ('BACKGROUND', (0, 0), (0, 1), colors.pink),
                    ('SPAN',(0,0),(0,1)),
                    ('BACKGROUND', (2, 2), (2, 3), colors.orange),
                    ('SPAN',(2,2),(2,3)),
                    ]
    t=Table(data,style=sty)
    lst.append(Paragraph("Illustrating splits with spans: nosplit", styleSheet['BodyText']))
    lst.append(t)
    lst.append(Spacer(0,6))
    lst.append(Paragraph("Illustrating splits with spans: split(4in,30)", styleSheet['BodyText']))
    for s in t.split(4*inch,30):
        lst.append(s)
        lst.append(Spacer(0,6))
    lst.append(Spacer(0,6))
    lst.append(Paragraph("Illustrating splits with spans: split(4in,36)", styleSheet['BodyText']))
    for s in t.split(4*inch,36):
        lst.append(s)
        lst.append(Spacer(0,6))
    lst.append(Paragraph("Illustrating splits with spans: split(4in,56)", styleSheet['BodyText']))
    lst.append(Spacer(0,6))
    for s in t.split(4*inch,56):
        lst.append(s)
        lst.append(Spacer(0,6))

    data=  [['00', '01', '02', '03', '04'],
            ['', '11', '12', '13', ''],
            ['20', '21', '22', '23', '24'],
            ['30', '31', '', '33', ''],
            ['40', '41', '', '43', '44']]
    sty=[
        ('GRID',(0,0),(-1,-1),0.5,colors.grey),
        ('GRID',(1,1),(-2,-2),1,colors.green),
        ('BOX',(0,0),(1,-1),2,colors.red),
        ('BOX',(0,0),(-1,-1),2,colors.black),
        ('LINEABOVE',(1,2),(-2,2),1,colors.blue),
        ('LINEBEFORE',(2,1),(2,-2),1,colors.pink),
        ('BACKGROUND', (0, 0), (0, 1), colors.pink),
        ('SPAN',(0,0),(0,1)),
        ('BACKGROUND',(-2,1),(-1,1),colors.palegreen),
        ('SPAN',(-2,1),(-1,1)),
        ('BACKGROUND',(-2,3),(-1,3),colors.yellow),
        ('SPAN',(-2,3),(-1,3)),
        ('BACKGROUND', (2, 3), (2, 4), colors.orange),
        ('SPAN',(2,3),(2,4)),
        ]

    t=Table(data,style=sty,repeatRows=2)
    lst.append(Paragraph("Illustrating splits with spans and repeatRows: nosplit", styleSheet['BodyText']))
    lst.append(t)
    lst.append(Spacer(0,6))
    if  1:
        lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,30)", styleSheet['BodyText']))
        for s in t.split(4*inch,30):
            lst.append(s)
            lst.append(Spacer(0,6))
        lst.append(Spacer(0,6))
        lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,36)", styleSheet['BodyText']))
        for s in t.split(4*inch,36):
            lst.append(s)
            lst.append(Spacer(0,6))
    lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,56)", styleSheet['BodyText']))
    lst.append(Spacer(0,6))
    for s in t.split(4*inch,56):
        lst.append(s)
        lst.append(Spacer(0,6))

    lst.append(PageBreak())
    from reportlab.lib.testutils import testsFolder
    I = Image(os.path.join(os.path.dirname(testsFolder),'tools','pythonpoint','demos','leftlogo.gif'))
    I.drawHeight = 1.25*inch*I.drawHeight / I.drawWidth
    I.drawWidth = 1.25*inch
    #I.drawWidth = 9.25*inch #uncomment to see better messaging
    P = Paragraph("<para align=center spaceb=3>The <b>ReportLab Left <font color=red>Logo</font></b> Image</para>", styleSheet["BodyText"])
    B = TableBarChart()
    BP = Paragraph("<para align=center spaceb=3>A bar chart in a cell.</para>", styleSheet["BodyText"])

    data=  [['A', 'B', 'C', Paragraph("<b>A pa<font color=red>r</font>a<i>graph</i></b><super><font color=yellow>1</font></super>",styleSheet["BodyText"]), 'D'],
            ['00', '01', '02', [I,P], '04'],
            ['10', '11', '12', [I,P], '14'],
            ['20', '21', '22', '23', '24'],
            ['30', '31', '32', '33', '34'],
            ['40', '41', '42', [B,BP], '44']]

    t=Table(data,style=[('GRID',(1,1),(-2,-2),1,colors.green),
                    ('BOX',(0,0),(1,-1),2,colors.red),
                    ('LINEABOVE',(1,2),(-2,2),1,colors.blue),
                    ('LINEBEFORE',(2,1),(2,-2),1,colors.pink),
                    ('BACKGROUND', (0, 0), (0, 1), colors.pink),
                    ('BACKGROUND', (1, 1), (1, 2), colors.lavender),
                    ('BACKGROUND', (2, 2), (2, 3), colors.orange),
                    ('BOX',(0,0),(-1,-1),2,colors.black),
                    ('GRID',(0,0),(-1,-1),0.5,colors.black),
                    ('VALIGN',(3,0),(3,0),'BOTTOM'),
                    ('BACKGROUND',(3,0),(3,0),colors.limegreen),
                    ('BACKGROUND',(3,1),(3,1),colors.khaki),
                    ('ALIGN',(3,1),(3,1),'CENTER'),
                    ('BACKGROUND',(3,2),(3,2),colors.beige),
                    ('ALIGN',(3,2),(3,2),'LEFT'),
                    ])

    t._argW[3]=1.5*inch
    lst.append(t)

    # now for an attempt at column spanning.
    lst.append(PageBreak())
    data=  [['A', 'BBBBB', 'C', 'D', 'E'],
            ['00', '01', '02', '03', '04'],
            ['10', '11', '12', '13', '14'],
            ['20', '21', '22', '23', '24'],
            ['30', '31', '32', '33', '34']]
    sty = [
            ('ALIGN',(0,0),(-1,-1),'CENTER'),
            ('VALIGN',(0,0),(-1,-1),'TOP'),
            ('GRID',(0,0),(-1,-1),1,colors.green),
            ('BOX',(0,0),(-1,-1),2,colors.red),

            #span 'BBBB' across middle 3 cells in top row
            ('SPAN',(1,0),(3,0)),
            #now color the first cell in this range only,
            #i.e. the one we want to have spanned.  Hopefuly
            #the range of 3 will come out khaki.
            ('BACKGROUND',(1,0),(1,0),colors.khaki),

            ('SPAN',(0,2),(-1,2)),


            #span 'AAA'down entire left column
            ('SPAN',(0,0), (0, 1)),
            ('BACKGROUND',(0,0),(0,0),colors.cyan),
            ('TEXTCOLOR', (0,'splitfirst'), (-1,'splitfirst'), colors.cyan),
            ('TEXTCOLOR', (0,'splitlast'), (-1,'splitlast'), colors.red),
            ('BACKGROUND', (0,'splitlast'), (-1,'splitlast'), colors.pink),
            ('LINEBELOW', (0,'splitlast'), (-1,'splitlast'), 1, colors.grey,'butt'),
           ]
    t=Table(data,style=sty, colWidths = [20] * 5, rowHeights = [20]*5)
    lst.append(t)
    lst.append(Spacer(18,18))

    t=Table(data,style=sty, colWidths = [20] * 5, rowHeights = [20]*5)
    for s in t.split(4*inch,72):
        lst.append(s)
        lst.append(Spacer(0,6))

    # now for an attempt at percentage widths
    lst.append(Spacer(18,18))
    lst.append(Paragraph("This table has colWidths=5*['14%']!", styleSheet['BodyText']))
    t=Table(data,style=sty, colWidths = ['14%'] * 5, rowHeights = [20]*5)
    lst.append(t)

    lst.append(Spacer(18,18))
    lst.append(Paragraph("This table has colWidths=['14%','10%','19%','22%','*']!", styleSheet['BodyText']))
    t=Table(data,style=sty, colWidths = ['14%','10%','19%','22%','*'], rowHeights = [20]*5)
    lst.append(t)

    # Mike's test example
    lst.append(Spacer(18,18))
    lst.append(Paragraph('Mike\'s Spanning Example', styleSheet['Heading1']))
    data=  [[Paragraph('World Domination: The First Five Years', styleSheet['BodyText']), ''],
            [Paragraph('World <font color="green">Domination</font>: The First Five Years', styleSheet['BodyText']),''],
            [Paragraph('World Domination: The First Five Years', styleSheet['BodyText']), ''],
            ]
    t=Table(data, style=[('SPAN',(0,0),(1,0)),('SPAN',(0,1),(1,1)),('SPAN',(0,2),(1,2)),], colWidths = [3*cm,8*cm], rowHeights = [None]*3)
    lst.append(t)

    lst.append(Spacer(18,18))
    lst.append(Paragraph('Mike\'s Non-spanning Example', styleSheet['Heading1']))
    data=  [[Paragraph('World Domination: The First Five Years', styleSheet['BodyText'])],
            [Paragraph('World <font color="magenta">Domination</font>: The First Five Years', styleSheet['BodyText'])],
            [Paragraph('World Domination: The First Five Years', styleSheet['BodyText'])],
            ]
    t=Table(data, style=[], colWidths = [11*cm], rowHeights = [None]*3)
    lst.append(t)

    lst.append(Spacer(18,18))
    lst.append(Paragraph('xpre example', styleSheet['Heading1']))
    data=  [    [
                XPreformatted('Account Details', styleSheet['Heading3']),
                '', XPreformatted('Client Details', styleSheet['Heading3']),
                ],  #end of row 0
            ]
    t=Table(data, style=[], colWidths = [80,230.0,80], rowHeights = [None]*1)
    lst.append(t)

    lst.append(PageBreak())

    lst.append(Paragraph('Trying colour cycling in background', styleSheet['Heading1']))
    lst.append(Paragraph("This should alternate pale blue and uncolored by row", styleSheet['BodyText']))
    data=  [['001', '01', '02', '03', '04', '05'],
            ['002', '01', '02', '03', '04', '05'],
            ['003', '01', '02', '03', '04', '05'],
            ['004', '01', '02', '03', '04', '05'],
            ['005', '01', '02', '03', '04', '05'],
            ['006', '01', '02', '03', '04', '05'],
            ['007', '01', '02', '03', '04', '05'],
            ['008', '01', '02', '03', '04', '05'],
            ['009', '01', '02', '03', '04', '05'],
            ['010', '01', '02', '03', '04', '05'],

            ]
    t=Table(data,style=[
                    ('GRID',(0,0),(-1,-1),0.5,colors.grey),
                    ('ROWBACKGROUNDS', (0, 0), (-1, -1), (0xD0D0FF, None)),
                    ])
    lst.append(t)
    lst.append(Spacer(0,6))
    lst.append(Paragraph("And this should pale blue, pale pink and None by column", styleSheet['BodyText']))
    data=  [['001', '01', '02', '03', '04', '05'],
            ['002', '01', '02', '03', '04', '05'],
            ['003', '01', '02', '03', '04', '05'],
            ['004', '01', '02', '03', '04', '05'],
            ['005', '01', '02', '03', '04', '05'],
            ['006', '01', '02', '03', '04', '05'],
            ['007', '01', '02', '03', '04', '05'],
            ['008', '01', '02', '03', '04', '05'],
            ['009', '01', '02', '03', '04', '05'],
            ['010', '01', '02', '03', '04', '05'],

            ]
    t=Table(data,style=[
                    ('GRID',(0,0),(-1,-1),0.5,colors.grey),
                    ('COLBACKGROUNDS', (0, 0), (-1, -1), (0xD0D0FF, 0xFFD0D0, None)),
                    ])
    lst.append(t)

    lst.append(PageBreak())
    lst.append(Paragraph("This spanning example illustrates automatic removal of grids and lines in spanned cells!", styleSheet['BodyText']))
    lst.append(Spacer(0,6))
    data=  [['Top\nLeft', '', '02', '03', '04', '05', '06', '07'],
            ['', '', '12', 'Span (3,1) (6,2)', '','','','17'],
            ['20', '21', '22', '', '','','','27'],
            ['30', '31', '32', '33', '34','35','36','37'],
            ['40', 'In The\nMiddle', '', '', '44','45','46','47'],
            ['50', '', '', '', '54','55','56','57'],
            ['60', '', '', '','64', '65', 'Bottom\nRight', ''],
            ['70', '71', '72', '73','74', '75', '', '']]
    t=Table(data,style=[
            ('GRID',(0,0),(-1,-1),0.5,colors.grey),
            ('BACKGROUND',(0,0),(1,1),colors.palegreen),
            ('SPAN',(0,0),(1,1)),
            ('BACKGROUND',(-2,-2),(-1,-1), colors.pink),
            ('SPAN',(-2,-2),(-1,-1)),
            ('SPAN',(1,4),(3,6)),
            ('BACKGROUND',(1,4),(3,6), colors.lightblue),
            ('SPAN',(3,1),(6,2)),
            ('BACKGROUND',(3,1),(6,2), colors.peachpuff),
            ('VALIGN',(3,1),(6,2),'TOP'),
            ('LINEABOVE', (0,2),(-1,2), 1, colors.black, 0, None, None, 2, 2),
            ('LINEBEFORE', (3,0),(3,-1), 1, colors.black, 0, None, None, 2, 2),
            ])
    lst.append(t)

    lst.append(PageBreak())

    lst.append(Paragraph("und jetzt noch eine Tabelle mit 5000 Zeilen:", styleSheet['BodyText']))
    sty = [ ('GRID',(0,0),(-1,-1),1,colors.green),
            ('BOX',(0,0),(-1,-1),2,colors.red),
           ]
    data = [[str(i), Paragraph("xx "* (i%10), styleSheet["BodyText"]), Paragraph("blah "*(i%40), styleSheet["BodyText"])] for i in range(500)]
    t=LongTable(data, style=sty, colWidths = [50,100,200])
    lst.append(t)

    #Yuan Hong's bug tester
    lst.append(PageBreak())
    lst.append(Paragraph('Yian Hong\'s Bug Case (should not blow up)', styleSheet['Heading2']))
    data = ([['Col1', 'Col2', 'Col3', 'Col4', 'Col5']]+
                [['01', Paragraph('This is cell one that contains a paragraph.', styleSheet['Normal']), '02', '03', '04']
                    for i in range(50)])

    t = Table(data, ['20%']*5, repeatRows=1)
    t.setStyle(TableStyle([
        ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
        ('BOX', (0,0), (-1,-1), 0.25, colors.black),
        ('SPAN', (0,50), (-2,50)),
        ]))

    lst.append(t)
    lst.append(PageBreak())

    #Volker Haas' example extended
    #the optimal row heights are the solution of an LP similar to
    #
    #Objective function
    #   min: 3*h0+3*h1+3*h2+2*h3;
    #
    #constraints
    #   h0>=12;
    #   h1>=12;
    #   h2>=12;
    #   h3>=12;
    #   h0+h1+h2>=48;
    #   h0+h1>=12;
    #   h2+h3>=60;
    #
    #the solution H=[12,12,24,36]
    def makeTable(x,y):
        return Table([
                ['00', '01', '02', '03', '04', '05\nline2\nline3\nline4'],
                ['', '11', '12', x, '',''],
                ['20', '21', y, '23', '24',''],
                ['30', '31', '', '33', '34','35'],
                ],
                style=[
                    ('TOPPADDING',(0,0),(-1,-1),0),
                    ('BOTTOMPADDING',(0,0),(-1,-1),0),
                    ('RIGHTPADDING',(0,0),(-1,-1),0),
                    ('LEFTPADDING',(0,0),(-1,-1),0),
                    ('GRID',(0,0),(-1,-1),0.5,colors.grey),
                    ('BACKGROUND', (0, 0), (0, 1), colors.pink),
                    ('SPAN',(0,0),(0,1)),
                    ('BACKGROUND', (2, 2), (2, 3), colors.orange),
                    ('SPAN',(2,2),(2,3)),
                    ('SPAN',(3,1),(4,1)),
                    ('SPAN',(5,0),(5,2)),
                ])
    p_style= ParagraphStyle('Normal')
    lst.append(makeTable(
            Paragraph('This is a string',p_style),
            Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style)
            ))

    lst.append(Spacer(10,10))
    lst.append(makeTable(
            XPreformatted('This is a string',p_style),
            Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style)
            ))
    lst.append(Spacer(10,10))
    lst.append(makeTable(
            'This is a string',
            '22\nblub\nasfd\nafd\nasdfs',
            ))
    lst.append(Spacer(10,10))
    lst.append(makeTable(
            'This is a string',
            Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style)
            ))
    SimpleDocTemplate(outputfile('test_platypus_tables_2.pdf'), showBoundary=1).build(lst)
    def test1(self):
        "This makes one long multi-page paragraph."

        # Build story.
        story = []
        styleSheet = getSampleStyleSheet()
        h3 = styleSheet['Heading3']
        bt = styleSheet['BodyText']
        text = '''If you imagine that the box of X's tothe left is
an image, what I want to be able to do is flow a
series of paragraphs around the image
so that once the bottom of the image is reached, then text will flow back to the
left margin. I know that it would be possible to something like this
using tables, but I can't see how to have a generic solution.
There are two examples of this in the demonstration section of the reportlab
site.
If you look at the "minimal" euro python conference brochure, at the end of the
timetable section (page 8), there are adverts for "AdSu" and "O'Reilly". I can
see how the AdSu one might be done generically, but the O'Reilly, unsure...
I guess I'm hoping that I've missed something, and that
it's actually easy to do using platypus.We can do greek letters <greek>mDngG</greek>. This should be a
u with a dieresis on top &lt;unichar code=0xfc/&gt;="<unichar code="0xfc"/>" and this &amp;#xfc;="&#xfc;" and this \\xc3\\xbc="\xc3\xbc". On the other hand this
should be a pound sign &amp;pound;="&pound;" and this an alpha &amp;alpha;="&alpha;". You can have links in the page <link href="http://www.reportlab.com" color="blue">ReportLab</link> &amp; <a href="http://www.reportlab.org" color="green">ReportLab.org</a>.
Use scheme "pdf:" to indicate an external PDF link, "http:", "https:" to indicate an external link eg something to open in
your browser. If an internal link begins with something that looks like a scheme, precede with "document:". <strike>This text should have a strike through it.</strike>
'''
        from reportlab.platypus.flowables import ImageAndFlowables, Image
        from reportlab.lib.testutils import testsFolder
        gif = os.path.join(testsFolder,'pythonpowered.gif')
        heading = Paragraph('This is a heading',h3)
        story.append(ImageAndFlowables(Image(gif),[heading,Paragraph(text,bt)]))
        phrase = 'This should be a paragraph spanning at least three pages. '
        description = ''.join([('%d: '%i)+phrase for i in xrange(250)])
        story.append(ImageAndFlowables(Image(gif),[heading,Paragraph(description, bt)],imageSide='left'))
        story.append(NextPageTemplate('special'))
        story.append(PageBreak())
        VERA = ('Vera','VeraBd','VeraIt','VeraBI')
        for v in VERA:
            registerFont(TTFont(v,v+'.ttf'))
        registerFontFamily(*(VERA[:1]+VERA))
        story.append(ImageAndFlowables(
                        Image(gif,width=280,height=120),
                        Paragraph('''<font name="Vera">The <b>concept</b> of an <i>integrated</i> one <b><i>box</i></b> solution for <i><b>advanced</b></i> voice and
data applications began with the introduction of the IMACS. The
IMACS 200 carries on that tradition with an integrated solution
optimized for smaller port size applications that the IMACS could not
economically address. An array of the most popular interfaces and
features from the IMACS has been bundled into a small 2U chassis
providing the ultimate in ease of installation.</font>''',
                        style=ParagraphStyle(
                                name="base",
                                fontName="Helvetica",
                                leading=12,
                                leftIndent=0,
                                firstLineIndent=0,
                                spaceBefore = 9.5,
                                fontSize=9.5,
                                )
                            ),
                    imageSide='left',
                    )
                )
        story.append(ImageAndFlowables(
                        Image(gif,width=240,height=120),
                        Paragraph('''The concept of an integrated one box solution for advanced voice and
data applications began with the introduction of the IMACS. The
IMACS 200 carries on that tradition with an integrated solution
optimized for smaller port size applications that the IMACS could not
economically address. An array of the most popular interfaces and
features from the IMACS has been bundled into a small 2U chassis
providing the ultimate in ease of installation.''',
                        style=ParagraphStyle(
                                name="base",
                                fontName="Helvetica",
                                leading=12,
                                leftIndent=0,
                                firstLineIndent=0,
                                spaceBefore = 9.5,
                                fontSize=9.5,
                                )
                            ),
                    imageSide='left',
                    )
                )

        story.append(PageBreak())
        story.append(Paragraph('Image larger than the frame',h3))
        story.append(ImageAndFlowables(
                        Image(gif,width=6*110,height=6*44),
                        Paragraph('''The concept of an integrated one box solution for advanced voice and
data applications began with the introduction of the IMACS. The
IMACS 200 carries on that tradition with an integrated solution
optimized for smaller port size applications that the IMACS could not
economically address. An array of the most popular interfaces and
features from the IMACS has been bundled into a small 2U chassis
providing the ultimate in ease of installation.''',
                        style=ParagraphStyle(
                                name="base",
                                fontName="Helvetica",
                                leading=12,
                                leftIndent=0,
                                firstLineIndent=0,
                                spaceBefore = 9.5,
                                fontSize=9.5,
                                )
                            ),
                    imageSide='left',
                    )
                )

        
        doc = MyDocTemplate(outputfile('test_platypus_imageandflowables.pdf'),showBoundary=1)
        doc.multiBuild(story)
styleN = styles['Normal']
styleH = styles['Heading1']
_style = ParagraphStyle('Courier',fontName="Courier", fontSize=10, leading = 15)
_styleD1 = ParagraphStyle('Courier',fontName="Courier", fontSize=9, leading = 15)
_stylePR = ParagraphStyle('Courier',fontName="Courier", fontSize=8)
_table_heading = ParagraphStyle('Courier',fontName="Courier", fontSize=7, leading = 10)
styles.add(ParagraphStyle(name='Wrap', fontSize=8, wordWrap='LTR', firstLineIndent = 0,alignment = TA_LEFT))
row = []
ctr = 0
tmpfilename=os.path.join(request.folder,'private',str(uuid4()))
# doc = SimpleDocTemplate(tmpfilename,pagesize=A4, rightMargin=20,leftMargin=20, topMargin=200,bottomMargin=200, showBoundary=1)
# doc = SimpleDocTemplate(tmpfilename,pagesize=A4, rightMargin=20,leftMargin=20, topMargin=2.1 * inch, bottomMargin=1.5 * inch)#, showBoundary=1)
doc = SimpleDocTemplate(tmpfilename,pagesize=A4, rightMargin=20,leftMargin=20, topMargin=2.7 * inch,bottomMargin=2.4 * inch)#, showBoundary=1)

_merchandpartners = request.folder + '/static/images/merchpartners.jpg' 
_img = Image(_merchandpartners)
_img.drawHeight = 2.55 *inch * _img.drawHeight / _img.drawWidth
_img.drawWidth = 3.25 * inch
_img.hAlign = 'CENTER'

_MerchAndPartners = Image(_merchandpartners, width = 550, height = 80, hAlign = 'CENTER')

_merchtrading = request.folder + '/static/images/merchtrading.jpg' 
_img = Image(_merchtrading)
_img.drawHeight = 2.55 *inch * _img.drawHeight / _img.drawWidth
_img.drawWidth = 3.25 * inch
_img.hAlign = 'CENTER'

_MerchTrading = Image(_merchtrading, width = 550, height = 80, hAlign = 'CENTER')

def get_account_voucher_canvas(canvas, doc):
Ejemplo n.º 28
0
 def add_image(self, src, width, height, align=CENTER):
     img = Image(src, width, height)
     img.hAlign = align
     self.add(img)
Ejemplo n.º 29
0
    def Imprimer(self, event=None):
        listeDates = self.dictImpression["dates"]
        if len(listeDates) > 26 :
            dlg = wx.MessageDialog(self, _(u"Désolé mais vous ne pouvez pas imprimer plus de 26 jours sur une feuille !"), _(u"Information"), wx.OK | wx.ICON_EXCLAMATION)
            dlg.ShowModal()
            dlg.Destroy()
            return False
        
        # Création du PDF
        from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, PageBreak
        from reportlab.platypus.flowables import ParagraphAndImage, Image
        from reportlab.rl_config import defaultPageSize
        from reportlab.lib.units import inch, cm
        from reportlab.lib.utils import ImageReader
        from reportlab.lib import colors
        from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
        self.hauteur_page = defaultPageSize[1]
        self.largeur_page = defaultPageSize[0]
        
        # Recherche le format de la page à appliquer
        largeurPremiereColonne = 140
        largeurColonnesDates = 24
        largeurMax = largeurPremiereColonne + (largeurColonnesDates*len(listeDates))
        
        if largeurMax <= 520 :
            # Format Portrait
            largeurPage, hauteurPage = defaultPageSize
            largeurContenu = 520
        else :
            # Format Paysage
            hauteurPage, largeurPage = defaultPageSize
            largeurContenu = 770

        # Initialisation du PDF
        nomDoc = FonctionsPerso.GenerationNomDoc("LISTE_TRANSPORTS", "pdf")
        if sys.platform.startswith("win") : nomDoc = nomDoc.replace("/", "\\")
        doc = SimpleDocTemplate(nomDoc, pagesize=(largeurPage, hauteurPage), topMargin=30, bottomMargin=30)
        story = []
        
        # Création du titre du document
        def Header():
            dataTableau = []
            largeursColonnes = ( (largeurContenu-100, 100) )
            dateDuJour = DateEngFr(str(datetime.date.today()))
            dataTableau.append( (_(u"Liste des transports"), _(u"%s\nEdité le %s") % (UTILS_Organisateur.GetNom(), dateDuJour)) )
            style = TableStyle([
                    ('BOX', (0,0), (-1,-1), 0.25, colors.black), 
                    ('VALIGN', (0,0), (-1,-1), 'TOP'), 
                    ('ALIGN', (0,0), (0,0), 'LEFT'), 
                    ('FONT',(0,0),(0,0), "Helvetica-Bold", 16), 
                    ('ALIGN', (1,0), (1,0), 'RIGHT'), 
                    ('FONT',(1,0),(1,0), "Helvetica", 6), 
                    ])
            tableau = Table(dataTableau, largeursColonnes)
            tableau.setStyle(style)
            story.append(tableau)
            story.append(Spacer(0,20))       
        
        # Insère un header
        Header() 
        
        # Contenu
        for dictCategorie in self.dictImpression["donnees"] :
            label = dictCategorie["texte"]
            img = dictCategorie["img"]
            elements = dictCategorie["elements"]
            
            dataTableau = []
            largeursColonnes = [largeurPremiereColonne,]
            
            # Création de la ligne de date
            paraStyle = ParagraphStyle(name="categorie",
                      fontName="Helvetica-Bold",
                      fontSize=9,
                      leading=8,
                      spaceAfter=2,)

            ligne = [ParagraphAndImage(Paragraph(label, paraStyle), Image(Chemins.GetStaticPath("Images/32x32/%s.png" % img), width=8, height=8), xpad=1, ypad=0, side="left"),]
            for date in listeDates :
                ligne.append(u"%02d/%02d\n%04d" % (date.day, date.month, date.year))
                largeursColonnes.append(largeurColonnesDates)
            dataTableau.append(ligne)
        
            # Création des lignes
            listeExtraStyles = []
            index = 1
            for element in elements :
                
                # Décoration de la ligne
                if element["type"] in ("lieux", "lignes", "localisations") :
                    listeExtraStyles.append(('BACKGROUND', (0, index), (-1, index), (0.8, 0.8, 1) ))

                if element["type"] == "arrets" :
                    listeExtraStyles.append(('BACKGROUND', (0, index), (-1, index), (0.9, 0.9, 1) ))

                if element["type"] == "heures" :
                    listeExtraStyles.append(('FONT',(0, index), (0, index), "Helvetica-Bold", 6),)
                    listeExtraStyles.append(('FONT',(1, index), (-1, index), "Helvetica", 5),)
                    listeExtraStyles.append(('TEXTCOLOR',(1, index), (-1, index), (0.6, 0.6, 0.6)),)

                if element["type"] == "individus" :
                    listeExtraStyles.append(('ALIGN', (0, index), (0, index), 'RIGHT'))
                    listeExtraStyles.append(('GRID', (1, index), (-1, index), 0.25, colors.black))
                    listeExtraStyles.append(('FONT',(1, index), (-1, index), "Helvetica", 6),)

                # Ajout d'une marge
                label = element["texte"]
                if "marge" in element :
                    label = u"%s%s" % ((element["marge"]-1) * "      ", label)
                ligne = [label,]
                
                # Ajout des colonnes
                for indexColonne in range(1, len(largeursColonnes)) :
                    label = u""
                    if "colonnes" in element:
                        if indexColonne in element["colonnes"] :
                            label = element["colonnes"][indexColonne]
                    ligne.append(label)
                
                dataTableau.append(ligne)
                index += 1
        
            # Style du tableau
            listeStyles = [
                    ('VALIGN', (0, 0), (-1,-1), 'MIDDLE'), 
                    ('ALIGN', (1, 0), (-1, -1), 'CENTRE'),
                    ('FONT',(0, 0), (-1,-1), "Helvetica", 7), 
                    ('FONT',(0, 0), (0, 0), "Helvetica-Bold", 8),
                    ('BOX', (0, 1), (-1, -1), 0.25, colors.black), 
                    ('GRID', (1, 0), (-1, 0), 0.25, colors.black), 
                    ]
            
            for extraStyle in listeExtraStyles :
                listeStyles.append(extraStyle)
                
            # Création du tableau
            tableau = Table(dataTableau, largeursColonnes)
            tableau.setStyle(TableStyle(listeStyles))
            story.append(tableau)
            story.append(Spacer(0, 15))
        
##        # TOTAUX
##        dataTableau = []
##        largeursColonnes = [220, 220, 40, 40]
##
##        for ligne in self.listeImpression["totaux"] :
##            dataTableau.append(ligne) 
##
##        couleurFond = (0.8, 0.8, 0.8)
##        listeStyles = [
##                ('VALIGN', (0,0), (-1,-1), 'MIDDLE'), # Centre verticalement toutes les cases
##                ('FONT',(0,0),(-1,-1), "Helvetica", 7), # Donne la police de caract. + taille de police 
##                ('BOX', (0, 1), (-1,-1), 0.25, colors.black), # Crée la bordure noire pour tout le tableau
##                ('ALIGN', (2, 0), (-1, -1), 'CENTRE'), # Ligne de labels colonne alignée au centre
##                ('BOX', (0, 0), (-1,0), 0.25, colors.black), # Crée la bordure noire du nom de famille
##                ('FONT',(0,0),(0,0), "Helvetica-Bold", 8), # Donne la police de caract. + taille de police du titre de groupe
##                ('BACKGROUND', (0,0), (-1,0), couleurFond), # Donne la couleur de fond du titre de groupe
##                ('TOPPADDING',(0,0),(-1,-1), 1), 
##                ('BOTTOMPADDING',(0,0),(-1,-1), 1), 
##                ]
##            
##        # Création du tableau
##        tableau = Table(dataTableau, largeursColonnes)
##        tableau.setStyle(TableStyle(listeStyles))
##        story.append(tableau)

        # Enregistrement du PDF
        doc.build(story)
        
        # Affichage du PDF
        FonctionsPerso.LanceFichierExterne(nomDoc)
Ejemplo n.º 30
0
def createUrgentCoverPage(page_size=PAGE_SIZE_LETTER,
                          total_pages=1,
                          recipient_name='',
                          recipient_phone='',
                          recipient_fax='',
                          sender_name='',
                          sender_phone='',
                          sender_fax='',
                          sender_email='',
                          regarding='',
                          message='',
                          preserve_formatting=False,
                          output=None):

    s = getSampleStyleSheet()

    story = []
    i = Image(os.path.join(prop.image_dir, 'other', 'urgent_title.png'),
              width=424,
              height=92)
    i.hAlign = 'LEFT'
    story.append(i)
    story.append(Spacer(1, inch))
    story.append(HRFlowable(width='100%', color='black'))

    ps = ParagraphStyle(
        name='normal',
        fontName='Times-Roman',
        #fontName='STSong-Light',
        #fontName='UMing',
        fontSize=12)

    recipient_name_label = Paragraph("To:", ps)
    recipient_name_text = Paragraph(escape(recipient_name[:64]), ps)

    recipient_fax_label = Paragraph("Fax:", ps)
    recipient_fax_text = Paragraph(escape(recipient_fax[:64]), ps)

    recipient_phone_label = Paragraph("Phone:", ps)
    recipient_phone_text = Paragraph(escape(recipient_phone[:64]), ps)

    sender_name_label = Paragraph("From:", ps)
    sender_name_text = Paragraph(escape(sender_name[:64]), ps)

    sender_phone_label = Paragraph("Phone:", ps)
    sender_phone_text = Paragraph(escape(sender_phone[:64]), ps)

    sender_email_label = Paragraph("Email:", ps)
    sender_email_text = Paragraph(escape(sender_email[:64]), ps)

    regarding_label = Paragraph("Regarding:", ps)
    regarding_text = Paragraph(escape(regarding[:128]), ps)

    date_time_label = Paragraph("Date:", ps)
    date_time_text = Paragraph(
        strftime("%a, %d %b %Y %H:%M:%S (%Z)", localtime()), ps)

    total_pages_label = Paragraph("Total Pages:", ps)
    total_pages_text = Paragraph("%d" % total_pages, ps)

    data = [
        [recipient_name_label, recipient_name_text],
        [recipient_fax_label, recipient_fax_text],
        ['', ''],
        [sender_name_label, sender_name_text],
        [sender_phone_label, sender_phone_text],
        [sender_email_label, sender_email_text],
        ['', ''],
        [date_time_label, date_time_text],
        [total_pages_label, total_pages_text],
        [regarding_label, regarding_text],
    ]

    LIST_STYLE = TableStyle([  #('LINEABOVE', (0,0), (-1,0), 2, colors.black),
        #('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
        #('LINEBELOW', (0,-1), (-1,-1), 2, colors.black),
        ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
        ('VALIGN', (0, 0), (-1, -1), 'TOP'),
    ])

    story.append(Table(data, style=LIST_STYLE))
    story.append(HRFlowable(width='100%', color='black'))

    if message:
        MSG_STYLE = TableStyle([  #('LINEABOVE', (0,0), (-1,0), 2, colors.black),
            #('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
            #('LINEBELOW', (0,-1), (-1,-1), 2, colors.black),
            ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
            ('VALIGN', (0, 0), (-1, -1), 'TOP'),
            #('SPAN', (-2, 1), (-1, -1)),
        ])

        #story.append(HRFlowable(width='100%', color='black'))
        story.append(Spacer(1, 0.5 * inch))

        #        if preserve_formatting:
        #            message = '\n'.join(message[:2048].splitlines()[:32])
        #
        #            data = [#[Paragraph("Comments/Notes:", ps), ''],
        #                    [Preformatted(escape(message), ps)],]
        #        else:
        #            data = [#[Paragraph("Comments/Notes:", ps), ''],
        #                    [Paragraph(escape(message[:2048]), ps), ''],]
        #
        #        #story.append(HRFlowable(width='100%', color='black'))
        #        #story.append(Table(data, style=MSG_STYLE))

        if preserve_formatting:
            message = '\n'.join(message[:2048].splitlines()[:32])
            story.append(Preformatted(escape(message), ps))
        else:
            story.append(Paragraph(escape(message), ps))

    if page_size == PAGE_SIZE_LETTER:
        pgsz = letter
    elif page_size == PAGE_SIZE_LEGAL:
        pgsz = legal
    else:
        pgsz = A4

    if output is None:
        f_fd, f = utils.make_temp_file()
    else:
        f = output

    doc = SimpleDocTemplate(f, pagesize=pgsz)
    doc.build(story)

    return f