Ejemplo n.º 1
0
def stylesheet():
    styles = {
        'default':
        ParagraphStyle('default'),
        'list_default':
        ListStyle(
            'list_default',
            leftIndent=18,
            rightIndent=0,
            spaceBefore=0,
            spaceAfter=0,
            bulletAlign='left',
            bulletType='1',
            bulletColor=black,
            bulletFontName='Helvetica',
            bulletFontSize=12,
            bulletOffsetY=0,
            bulletDedent='auto',
            bulletDir='ltr',
        )
    }
    styles['list_special'] = ListStyle(
        'list_special',
        parent=styles['list_default'],
        spaceBefore=12,
        spaceAfter=12,
        bulletColor='purple',
        bulletFontName='Courier-Bold',
        bulletFontSize=8,
        bulletOffsetY=-1,
        bulletDedent=-180,
        bulletDir='rtl',
        bulletType='I',
    )
    return styles
Ejemplo n.º 2
0
def create_base_stylesheet():
    stylesheet = StyleSheet1()
    stylesheet.add(
        ParagraphStyle(name='Normal',
                       fontName='Times-Roman',
                       fontSize=16,
                       leading=18,
                       spaceAfter=5))
    stylesheet.add(
        ListStyle(
            name='UnorderedList',
            parent=None,
            leftIndent=18,
            rightIndent=0,
            bulletAlign='left',
            bulletType='1',
            bulletColor=colors.black,
            bulletFontName='Times-Roman',
            bulletFontSize=16,
            bulletOffsetY=0,
            bulletDedent='auto',
            bulletDir='ltr',
            bulletFormat=None,
            #start='circle square blackstar sparkle disc diamond'.split(),
            start=None,
        ),
        alias='ul')
    return stylesheet
    def __init__(self, buffer, vouchers):
        self.buffer = buffer
        self.vouchers = vouchers
        self.pagesize = A5
        self.width, self.height = self.pagesize

        pdfmetrics.registerFont(
            TTFont("DejaVu Sans", "assets/fonts/DejaVuSans.ttf"))
        pdfmetrics.registerFont(
            TTFont("DejaVu Sans Bold", "assets/fonts/DejaVuSans-Bold.ttf"))
        addMapping('DejaVu Sans', 0, 0, 'DejaVu Sans')
        addMapping('DejaVu Sans', 1, 0, 'DejaVu Sans Bold')

        self.styles = getSampleStyleSheet()
        self.styles.add(
            ParagraphStyle(
                name='Text',
                fontName='DejaVu Sans',
                fontSize=8,
            ))
        self.styles.add(
            ParagraphStyle(name='Voucher_Subtitle',
                           fontName='DejaVu Sans',
                           fontSize=5,
                           alignment=TA_RIGHT))
        self.styles.add(
            ListStyle('list_default',
                      bulletType='bullet',
                      start='circle',
                      leftIndent=10,
                      bulletOffsetY=0,
                      bulletFontSize=7))
    def set_up_styles(self, *args, **kwargs):
        """
        Helper formatting methods assume the following styles have been defined:
            * Normal: format_question, get_metadata_page
            * Notes: get_metadata_page
            * Answers: format_answer, get_metadata_page
            * AnswersList: format_answer_list, get_metadata_page
            * Heading4: get_metadata_page, PDFFullReport.generate_pdf_report, PDFMatchReport.generate_match_report
            * Heading3: get_metadata_page, PDFMatchReport.generate_match_report
        If you override this method but don't define these styles, you will need to also override init and potentially
        the corresponding formatting methods.
        :return: a ReportLab stylesheet
        """
        def get_font_location(filename):
            return settings.APPS_DIR.path("fonts")(filename)

        styles = getSampleStyleSheet()
        headline_style = styles["Heading1"]
        headline_style.alignment = TA_CENTER
        headline_style.fontSize = 48

        subtitle_style = styles["Heading2"]
        subtitle_style.fontSize = 24
        subtitle_style.leading = 26
        subtitle_style.alignment = TA_CENTER

        report_title_style = styles["Heading3"]
        report_title_style.fontSize = 28
        report_title_style.leading = 36
        report_title_style.spaceBefore = 0
        report_title_style.alignment = TA_CENTER

        section_title_style = styles["Heading4"]
        section_title_style.fontSize = 18
        section_title_style.leading = 22
        section_title_style.spaceBefore = 20

        body_style = styles["Normal"]
        body_style.fontSize = 14
        body_style.leading = 17
        body_style.leftIndent = 25

        styles.add(
            ParagraphStyle(
                name="Notes",
                parent=styles["Normal"],
                fontSize=10,
                leading=14,
                leftIndent=45,
                alias="notes",
            ))
        styles.add(ListStyle(name="AnswersList"))
        styles.add(
            ParagraphStyle(name="Answers",
                           parent=styles["Normal"],
                           leftIndent=0,
                           alias="answers"))

        return styles
Ejemplo n.º 5
0
def go():
    doc = SimpleDocTemplate("docs/donimoes.pdf")
    styles = getSampleStyleSheet()
    paragraph_style = styles[Styles.Normal]
    list_style = ListStyle('default_list',
                           bulletFontSize=paragraph_style.fontSize,
                           bulletFormat='%s.')
    story = []
    f = open('docs/rules.md')
    group = []
    bulleted = []
    first_bullet = None
    states = parse(f.read())
    for state in states:
        if state.style == Styles.Diagram:
            flowable = Diagram(state.text)
        else:
            flowable = Paragraph(state.text, styles[state.style])
        if state.style.startswith(Styles.Heading):
            group.append(flowable)
        elif state.bullet:
            bulleted.append(flowable)
            first_bullet = first_bullet or state.bullet
        else:
            if bulleted:
                story.append(
                    ListFlowable(bulleted,
                                 style=list_style,
                                 start=first_bullet))
                bulleted = []
                first_bullet = None
                story.append(Spacer(1, 0.055 * inch))
            if not group:
                story.append(flowable)
            else:
                group.append(flowable)
                story.append(KeepTogether(group))
                group = []
            story.append(Spacer(1, 0.055 * inch))
    if bulleted:
        story.append(
            ListFlowable(bulleted, style=list_style, start=first_bullet))
    doc.build(story, onFirstPage=firstPage)
Ejemplo n.º 6
0
    textColor="white",
    backColor="black",
    alignment=TA_CENTER,
    fontSize=8,
    leading=11,
    leftIndent=-35,
    rightIndent=0,
)

styles["bullet"] = ListStyle(
    "list_default",
    leftIndent=20,
    rightIndent=0,
    spaceBefore=0,
    spaceAfter=5,
    bulletAlign="right",
    bulletType="bullet",
    bulletColor="black",
    bulletFontName="Helvetica",
    bulletFontSize=5,
    bulletOffsetY=-3,
    fontName="Times-Roman",
)

styles["rotated_detail_incident"] = ParagraphStyle(
    "detail",
    parent=styles["detail-utc"],
    textColor="white",
    backColor="black",
    alignment=TA_CENTER,
    fontSize=8,
    leading=11,
Ejemplo n.º 7
0
    def set_up_styles(self, *args, **kwargs):
        """
        Helper formatting methods assume the following styles have been defined:
            * Normal: format_question, get_metadata_page
            * Notes: get_metadata_page
            * Answers: format_answer, get_metadata_page
            * AnswersList: format_answer_list, get_metadata_page
            * Heading4: get_metadata_page, generate_pdf_report, generate_match_report
            * Heading3: get_metadata_page, generate_match_report
        If you override this method but don't define these styles, you will need to also override init and potentially
        the corresponding formatting methods.
        :return: a ReportLab stylesheet
        """
        def get_font_location(filename):
            return settings.APPS_DIR.path('fonts')(filename)

        # pdfmetrics.registerFont(TTFont('Montserrat', get_font_location('Montserrat-Regular.ttf')))
        # pdfmetrics.registerFont(TTFont('OpenSans', get_font_location('OpenSans-Regular.ttf')))
        # pdfmetrics.registerFont(TTFont('OpenSans-Bold', get_font_location('OpenSans-ExtraBold.ttf')))
        # pdfmetrics.registerFont(TTFont('OpenSans-Italic', get_font_location('OpenSans-Italic.ttf')))
        # pdfmetrics.registerFont(TTFont('DejaVuSans', get_font_location('DejaVuSans.ttf')))
        # pdfmetrics.registerFontFamily('OpenSans', normal='OpenSans', bold='OpenSans-Bold', italic='OpenSans-Italic')

        styles = getSampleStyleSheet()
        headline_style = styles["Heading1"]
        headline_style.alignment = TA_CENTER
        headline_style.fontSize = 48
        #headline_style.fontName = 'Montserrat'

        subtitle_style = styles["Heading2"]
        subtitle_style.fontSize = 24
        #subtitle_style.fontName = 'OpenSans'
        subtitle_style.leading = 26
        subtitle_style.alignment = TA_CENTER

        report_title_style = styles["Heading3"]
        report_title_style.fontSize = 28
        #report_title_style.fontName = 'Montserrat'
        report_title_style.leading = 36
        report_title_style.spaceBefore = 0
        report_title_style.alignment = TA_CENTER

        section_title_style = styles["Heading4"]
        section_title_style.fontSize = 18
        #section_title_style.fontName = 'Montserrat'
        section_title_style.leading = 22
        section_title_style.spaceBefore = 20

        body_style = styles["Normal"]
        body_style.fontSize = 14
        #body_style.fontName = 'OpenSans'
        body_style.leading = 17
        body_style.leftIndent = 25

        styles.add(
            ParagraphStyle(name='Notes',
                           parent=styles['Normal'],
                           fontSize=10,
                           leading=14,
                           leftIndent=45,
                           alias='notes'))
        styles.add(
            ListStyle(name='AnswersList',
                      #bulletFontName='DejaVuSans',
                      ))

        styles.add(
            ParagraphStyle(name='Answers',
                           parent=styles['Normal'],
                           leftIndent=0,
                           alias='answers'))

        return styles
Ejemplo n.º 8
0
def stylesheet():
    styles = {
        'default':
        ParagraphStyle(
            'default',
            fontName='Times-Roman',
            fontSize=8,
            leading=12,
            leftIndent=0,
            rightIndent=0,
            firstLineIndent=0,
            alignment=TA_LEFT,
            spaceBefore=0,
            spaceAfter=0,
            bulletFontName='Times-Roman',
            bulletFontSize=2,
            bulletIndent=0,
            textColor=black,
            backColor=None,
            wordWrap='LTR',
            borderWidth=0,
            borderPadding=0,
            borderColor=None,
            borderRadius=None,
            allowWidows=1,
            allowOrphans=0,
            textTransform=None,  # 'uppercase' | 'lowercase' | None
            endDots=None,
            splitLongWords=1,
        ),
    }
    styles['title'] = ParagraphStyle(
        'title',
        parent=styles['default'],
        fontName='Courier-Oblique',
        fontSize=20,
        leading=42,
        alignment=TA_CENTER,
        textColor=black,
        spaceBefore=70,
        spaceAfter=70,
    )
    styles['subheading'] = ParagraphStyle(
        'subheading',
        parent=styles['default'],
        fontName='Helvetica',
        fontSize=14,
        leading=42,
        alignment=TA_LEFT,
        textColor=black,
    )
    styles['alert'] = ParagraphStyle(
        'alert',
        parent=styles['default'],
        leading=14,
        backColor=gainsboro,
        borderColor=black,
        borderWidth=1,
        borderPadding=5,
        borderRadius=2,
        spaceBefore=20,
        spaceAfter=20,
    )
    styles['footer'] = ParagraphStyle(
        'footer',
        parent=styles['default'],
        leading=14,
        backColor=gainsboro,
        borderColor=black,
        borderWidth=1,
        borderPadding=5,
        borderRadius=2,
        spaceBefore=50,
        spaceAfter=0,
        alignment=TA_CENTER,
    )
    styles['spacer'] = ParagraphStyle(
        'spacer',
        parent=styles['default'],
        spaceBefore=25,
        spaceAfter=25,
        alignment=TA_CENTER,
    )
    styles['tabletext'] = ParagraphStyle(
        'tabletext',
        parent=styles['default'],
        spaceBefore=0,
        spaceAfter=0,
        alignment=TA_CENTER,
        wordwrap='LTR',
        fontName='Helvetica',
        fontSize=5,
    )
    styles['table'] = TableStyle([
        ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
        ('FONT', (0, 0), (-1, 0), 'Helvetica-Bold'),
        ('FONTSIZE', (0, 0), (-1, 0), 8),
        ('TEXTCOLOR', (1, 1), (-1, -1), black),
        # ('VALIGN', (0,0), (0,-1), 'TOP'),
        ('INNERGRID', (0, 0), (-1, -1), 0.25, black),
        ('BOX', (0, 0), (-1, -1), 0.5, black),
        ('FONTSIZE', (0, 0), (-1, -1), 5),
        ('LEFTPADDING', (0, 0), (-1, -1), 2),
        ('RIGHTPADDING', (0, 0), (-1, -1), 2)
    ])
    styles['list_default'] = ListStyle(
        'list_default',
        leftIndent=18,
        rightIndent=0,
        spaceBefore=0,
        spaceAfter=0,
        bulletAlign='left',
        # bulletType='bullet',
        bulletColor=black,
        # bulletFontName='Helvetica',
        bulletFontSize=8,
        bulletOffsetY=0,
        bulletDedent='auto',
        bulletDir='ltr',
    )
    return styles
Ejemplo n.º 9
0
def generate_extended_report(report, the_file, report_data):
    styles = getSampleStyleSheet()
    styles.add(
        ParagraphStyle(name='LatoNormal',
                       parent=styles['Normal'],
                       fontName='Lato'))
    styles.add(
        ParagraphStyle(name='LatoTitle',
                       parent=styles['Normal'],
                       fontName='Lato-Bold',
                       fontSize=16))
    styles.add(
        ListStyle(name='LatoList', bulletFontName='Lato', bulletType='bullet'))

    volume_explanation = \
"""
Over the last month the average volume for the keywords "{keywords}" was {avg_vol} articles per day with a
minimum of {min_vol} and maximum of {max_vol}. The 95% confidence interval is {conf_min} to {conf_max};
this week there where {outside_conf} days where the volume of articles was exceptional.
"""

    volume_explanation = volume_explanation.format(
        keywords=report.query,
        avg_vol=int(report_data['volume_stats_data']['avg']),
        min_vol=int(report_data['volume_stats_data']['min']),
        max_vol=int(report_data['volume_stats_data']['max']),
        conf_min=int(
            report_data['volume_stats_data']['std_deviation_bounds']['lower']),
        conf_max=int(
            report_data['volume_stats_data']['std_deviation_bounds']['upper']),
        outside_conf=sum([
            1 if int(vol) > int(report_data['volume_stats_data']
                                ['std_deviation_bounds']['upper']) else 0
            for (_, vol) in report_data['volume_chart_data'][0]
        ]))

    elements = [
        Paragraph('Media Scan: %s' % report.title, styles['LatoTitle']),
        Spacer(width=1, height=20),
        MyPlainVolumeChart(data=report_data['volume_chart_data']),
        Paragraph(volume_explanation, styles['LatoNormal']),
        Spacer(width=1, height=10),
        Paragraph(
            'On %d, the day with highest volume, the top articles were:' %
            report_data['highest_day'], styles['LatoNormal']),
        ListFlowable([
            Paragraph(title, styles['LatoNormal'])
            for title in report_data['titles_highest']
        ],
                     start=None,
                     style=styles['LatoList'])
    ]

    def add_header(canvas, doc):
        canvas.saveState()
        canvas.drawImage('feed_harvesting/static/reportly.png',
                         20,
                         A4[1] - 35,
                         width=85,
                         height=21,
                         mask='auto')
        canvas.setFont('Lato', 10)
        canvas.drawRightString(A4[0] - 20, A4[1] - 25, "www.reportly.nl")
        canvas.drawRightString(A4[0] - 20, A4[1] - 35, "*****@*****.**")
        canvas.line(x1=20, y1=A4[1] - 45, x2=A4[0] - 20, y2=A4[1] - 45)
        canvas.line(x1=20, y1=45, x2=A4[0] - 20, y2=45)
        canvas.restoreState()

    doc = SimpleDocTemplate(the_file, pagesize=A4, initialFontName='Lato')
    doc.build(elements, onFirstPage=add_header, onLaterPages=add_header)

    the_file.seek(0)