Python reportlab.lib.styles.getSampleStyleSheet() Examples

The following are 23 code examples of reportlab.lib.styles.getSampleStyleSheet(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module reportlab.lib.styles , or try the search function .
Example #1
Source File: report.py    From nanopype with MIT License 7 votes vote down vote up
def __init__(self, cwd, output, version=''):
        self.cwd = cwd
        self.tag = os.path.basename(os.path.normpath(self.cwd))
        self.version = version
        self.story = []
        stylesheet = getSampleStyleSheet()
        self.title_style = stylesheet['Title']
        self.heading_style = stylesheet['Heading2']
        self.heading2_style = stylesheet['Heading3']
        self.normal_style = stylesheet['Normal']
        self.body_style = stylesheet['BodyText']
        self.current_section = 0
        self.doc = doc = SimpleDocTemplate(output,
            pagesize=A4,
            leftMargin=2.2*cm, rightMargin=2.2*cm,
            topMargin=1.5*cm,bottomMargin=2.5*cm)
        self.plot_width = self.doc.width * 0.85
        self.plot_scale = 0.4 
Example #2
Source File: generic_pdf.py    From multiscanner with Mozilla Public License 2.0 7 votes vote down vote up
def __init__(self, pdf_components):
        self.style = getSampleStyleSheet()
        self.style['Normal'].leading = 16
        self.style.add(ParagraphStyle(name='centered', alignment=TA_CENTER))
        self.style.add(ParagraphStyle(name='centered_wide', alignment=TA_CENTER,
                                      leading=18))
        self.style.add(ParagraphStyle(name='section_body',
                                      parent=self.style['Normal'],
                                      spaceAfter=inch * .05,
                                      fontSize=11))
        self.style.add(ParagraphStyle(name='bullet_list',
                                      parent=self.style['Normal'],
                                      fontSize=11))
        if six.PY3:
            self.buffer = six.BytesIO()
        else:
            self.buffer = six.StringIO()
        self.firstPage = True
        self.document = SimpleDocTemplate(self.buffer, pagesize=letter,
                                          rightMargin=12.7 * mm, leftMargin=12.7 * mm,
                                          topMargin=120, bottomMargin=80)

        self.tlp_color = pdf_components.get('tlp_color', '')
        self.pdf_components = pdf_components
        self.pdf_list = [] 
Example #3
Source File: pygments2xpre.py    From stdm with GNU General Public License v2.0 7 votes vote down vote up
def convertSourceFiles(filenames):
    "Helper function - makes minimal PDF document"

    from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, XPreformatted
    from reportlab.lib.styles import getSampleStyleSheet
    styT=getSampleStyleSheet()["Title"]
    styC=getSampleStyleSheet()["Code"]
    doc = SimpleDocTemplate("pygments2xpre.pdf")
    S = [].append
    for filename in filenames:
        S(Paragraph(filename,style=styT))
        src = open(filename, 'r').read()
        fmt = pygments2xpre(src)
        S(XPreformatted(fmt, style=styC))
    doc.build(S.__self__)
    print 'saved pygments2xpre.pdf' 
Example #4
Source File: MyPDFDocument.py    From FAE with GNU General Public License v3.0 6 votes vote down vote up
def generate_style(self, font_name=None, font_size=None):
        super(MyPdfDocument, self).generate_style(font_name, font_size)

        _styles = getSampleStyleSheet()

        self.style.normal = copy.deepcopy(_styles['Normal'])
        self.style.normal.alignment = 4
        self.style.normal.fontName = '%s' % self.style.fontName
        self.style.normal.fontSize = self.style.fontSize
        self.style.normal.firstLineIndent = 0.4 * cm
        self.style.normal.spaceBefore = self.style.fontSize * 1.5
        # normal.textColor = '#0e2b58'

        self.style.end_connection = copy.deepcopy(_styles['Normal'])
        self.style.end_connection.alignment = 0
        self.style.end_connection.fontName = '%s-Bold' % self.style.fontName
        self.style.end_connection.fontSize = self.style.fontSize
        self.style.end_connection.spaceBefore = self.style.fontSize * 3

        self.style.table_header = copy.deepcopy(self.style.normal)
        self.style.table_header.alignment = TA_CENTER 
Example #5
Source File: builder.py    From tia with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, doc_or_path, coverpage=None, pagesize=None, stylesheet=None, showBoundary=0):
        self.path = None
        if isinstance(doc_or_path, basestring):
            self.path = doc_or_path
            doc = self.build_doc(doc_or_path, pagesize=pagesize, showBoundary=showBoundary)

        self.doc = doc
        self.pagesize = doc.pagesize
        self.width, self.height = self.pagesize
        self.inc_cover = inc_coverpage = coverpage is not None
        self.template_defs = {}
        self.story = []
        self.active_template_id = None
        self.stylesheet = stylesheet or getSampleStyleSheet()
        if inc_coverpage:
            # Allow user to override the cover page template
            if not self.get_page_template('cover', err=0):
                f = Frame(0, 0, self.width, self.height)
                pt = PageTemplate(id='cover', frames=[f], onPage=coverpage.onPage)
                self.add_page_template(pt) 
Example #6
Source File: para.py    From stdm with GNU General Public License v2.0 6 votes vote down vote up
def buildContext(stylesheet=None):
    result = {}
    from reportlab.lib.styles import getSampleStyleSheet
    if stylesheet is not None:
        # Copy styles with the same name as aliases
        for (stylenamekey, stylenamevalue) in DEFAULT_ALIASES.items():
            if stylenamekey in stylesheet:
                result[stylenamekey] = stylesheet[stylenamekey]
        # Then make aliases
        for (stylenamekey, stylenamevalue) in DEFAULT_ALIASES.items():
            if stylenamevalue in stylesheet:
                result[stylenamekey] = stylesheet[stylenamevalue]

    styles = getSampleStyleSheet()
    # Then, fill in defaults if they were not filled yet.
    for (stylenamekey, stylenamevalue) in DEFAULT_ALIASES.items():
        if stylenamekey not in result and stylenamevalue in styles:
            result[stylenamekey] = styles[stylenamevalue]
    return result 
Example #7
Source File: api.py    From callisto-core with GNU Affero General Public License v3.0 6 votes vote down vote up
def get_cover_page(self, report_id, recipient):
        # title = f"{self.report_title} No.: {report_id}"

        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

        CoverPage = []
        logo = os.path.join(settings.BASE_DIR, self.logo_path)

        image = Image(logo, 3 * inch, 3 * inch)
        CoverPage.append(image)
        CoverPage.append(Spacer(1, 18))
        CoverPage.append(Paragraph("CONFIDENTIAL", headline_style))
        # paragraph = Paragraph(
        #     f"Intended for: {recipient}, Title IX Coordinator", subtitle_style)
        # CoverPage.append(paragraph)
        CoverPage.append(PageBreak())
        return CoverPage

    # entrypoints 
Example #8
Source File: para.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def buildContext(stylesheet=None):
    result = {}
    from reportlab.lib.styles import getSampleStyleSheet
    if stylesheet is not None:
        # Copy styles with the same name as aliases
        for stylenamekey, stylenamevalue in DEFAULT_ALIASES.items():
            if stylenamekey in stylesheet:
                result[stylenamekey] = stylesheet[stylenamekey]
        # Then make aliases
        for stylenamekey, stylenamevalue in DEFAULT_ALIASES.items():
            if stylenamevalue in stylesheet:
                result[stylenamekey] = stylesheet[stylenamevalue]

    styles = getSampleStyleSheet()
    # Then, fill in defaults if they were not filled yet.
    for stylenamekey, stylenamevalue in DEFAULT_ALIASES.items():
        if stylenamekey not in result and stylenamevalue in styles:
            result[stylenamekey] = styles[stylenamevalue]
    return result 
Example #9
Source File: para.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def defaultContext():
    result = {}
    from reportlab.lib.styles import getSampleStyleSheet
    styles = getSampleStyleSheet()
    for stylenamekey, stylenamevalue in DEFAULT_ALIASES.items():
        result[stylenamekey] = styles[stylenamevalue]
    return result 
Example #10
Source File: pygments2xpre.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def convertSourceFiles(filenames):
    "Helper function - makes minimal PDF document"

    from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, XPreformatted
    from reportlab.lib.styles import getSampleStyleSheet
    styT=getSampleStyleSheet()["Title"]
    styC=getSampleStyleSheet()["Code"]
    doc = SimpleDocTemplate("pygments2xpre.pdf")
    S = [].append
    for filename in filenames:
        S(Paragraph(filename,style=styT))
        src = open(filename, 'r').read()
        fmt = pygments2xpre(src)
        S(XPreformatted(fmt, style=styC))
    doc.build(S.__self__)
    print('saved pygments2xpre.pdf') 
Example #11
Source File: templates.py    From HH---POS-Accounting-and-ERP-Software with MIT License 5 votes vote down vote up
def __init__(self, invoice_path, pdf_info=None, precision='0.01'):
        if not pdf_info:
            pdf_info = self.default_pdf_info

        SimpleDocTemplate.__init__(
            self,
            invoice_path,
            pagesize=letter,
            rightMargin=inch,
            leftMargin=inch,
            topMargin=inch,
            bottomMargin=inch,
            **pdf_info.__dict__
        )

        self.precision = precision

        self._defined_styles = getSampleStyleSheet()
        self._defined_styles.add(
            ParagraphStyle('RightHeading1', parent=self._defined_styles.get('Heading1'), alignment=TA_RIGHT)
        )
        self._defined_styles.add(
            ParagraphStyle('TableParagraph', parent=self._defined_styles.get('Normal'), alignment=TA_CENTER)
        )

        self.invoice_info = None
        self.service_provider_info = None
        self.client_info = None
        self.is_paid = False
        self._items = []
        self._item_discount_rate = None
        self._transactions = []
        self._story = []
        self._bottom_tip = None
        self._bottom_tip_align = None
        self._amount_recieved = None 
Example #12
Source File: report_delivery.py    From callisto-core with GNU Affero General Public License v3.0 5 votes vote down vote up
def headline_style(self):
        styles = getSampleStyleSheet()
        headline_style = styles["Heading1"]
        headline_style.alignment = TA_CENTER
        headline_style.fontSize = 48
        return headline_style 
Example #13
Source File: report_delivery.py    From callisto-core with GNU Affero General Public License v3.0 5 votes vote down vote up
def subtitle_style(self):
        styles = getSampleStyleSheet()
        subtitle_style = styles["Heading2"]
        subtitle_style.fontSize = 24
        subtitle_style.leading = 26
        subtitle_style.alignment = TA_CENTER
        return subtitle_style 
Example #14
Source File: flowables.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def wrap(self,aW,aH):
        value = self.get_value(aW,aH)
        P = self.klass
        if not P:
            from reportlab.platypus.paragraph import Paragraph as P
        style = self.style
        if not style:
            from reportlab.lib.styles import getSampleStyleSheet
            style=getSampleStyleSheet()['Code']
        if self.escape:
            from xml.sax.saxutils import escape
            value=escape(value)
        self.add_content(P(value,style=style))
        return 0,0 
Example #15
Source File: flowables.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def wrap(self,aW,aH):
        value = self.get_value(aW,aH)
        P = self.klass
        if not P:
            from reportlab.platypus.paragraph import Paragraph as P
        style = self.style
        if not style:
            from reportlab.lib.styles import getSampleStyleSheet
            style=getSampleStyleSheet()['Code']
        if self.escape:
            from xml.sax.saxutils import escape
            value=escape(value)
        self.add_content(P(value,style=style))
        return 0,0 
Example #16
Source File: para.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def defaultContext():
    result = {}
    from reportlab.lib.styles import getSampleStyleSheet
    styles = getSampleStyleSheet()
    for (stylenamekey, stylenamevalue) in DEFAULT_ALIASES.items():
        result[stylenamekey] = styles[stylenamevalue]
    return result 
Example #17
Source File: templates.py    From PyInvoice with MIT License 5 votes vote down vote up
def __init__(self, invoice_path, pdf_info=None, precision='0.01'):
        if not pdf_info:
            pdf_info = self.default_pdf_info

        SimpleDocTemplate.__init__(
            self,
            invoice_path,
            pagesize=letter,
            rightMargin=inch,
            leftMargin=inch,
            topMargin=inch,
            bottomMargin=inch,
            **pdf_info.__dict__
        )

        self.precision = precision

        self._defined_styles = getSampleStyleSheet()
        self._defined_styles.add(
            ParagraphStyle('RightHeading1', parent=self._defined_styles.get('Heading1'), alignment=TA_RIGHT)
        )
        self._defined_styles.add(
            ParagraphStyle('TableParagraph', parent=self._defined_styles.get('Normal'), alignment=TA_CENTER)
        )

        self.invoice_info = None
        self.service_provider_info = None
        self.client_info = None
        self.is_paid = False
        self._items = []
        self._item_tax_rate = None
        self._transactions = []
        self._story = []
        self._bottom_tip = None
        self._bottom_tip_align = None 
Example #18
Source File: builder.py    From tia with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def build_page(self, template_id, flowable_map):
        """Build a pdf page by looking up the specified template and then mapping the flowable_map items to the
        appropriate named Frame
        """
        pt = self.get_page_template(template_id)
        # If this is the first page then ensure the page template is ordered first and no breaks or changes
        # are requested otherwise blank page shows up
        if self.active_template_id is None:
            self.make_template_first(template_id)
            self.story.append(NextPageTemplate(template_id))
            self.inc_cover and self.story.append(PageBreak())
            self.active_template_id = template_id
        elif self.active_template_id == template_id:
            # TODO - understand why this is necessary to not get a blank page between pages
            self.story.append(PageBreak())
        else:
            self.story.append(NextPageTemplate(template_id))
            self.story.append(PageBreak())
            self.active_template_id = template_id

        for idx, frame in enumerate(pt.frames):
            if frame.id not in flowable_map:
                # Add a note to the template to show that nothing was defined for this area
                self.story.append(Paragraph('NOT DEFINED: %s' % frame.id, getSampleStyleSheet()['Normal']))
            else:
                flowables = flowable_map[frame.id]
                if not isinstance(flowables, Flowable) and hasattr(flowables, '__iter__'):
                    [self.story.append(f) for f in flowables]
                else:
                    self.story.append(flowables)
            if idx < (len(pt.frames) - 1):
                self.story.append(FrameBreak())
        return self 
Example #19
Source File: sample.py    From tia with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def sample1():
    pdf_path = os.path.join(tempfile.gettempdir(), 'pdf_test_4.pdf')
    cols = ['pct', 'int', 'k', 'M', '$', 'date']
    df = pd.DataFrame(np.random.randn(40, len(cols)), columns=cols)
    df['int'] = 10000. * df['pct']
    df['k'] = 50000. * df['pct']
    df['M'] = 5000000. * df['pct']
    df['$'] = 500000. * df['pct']
    df['date'] = pd.date_range('1/1/2010', periods=len(df.index))
    df['id'] = 'ID-1'
    # Make this a multi-index frame
    df2 = df.copy()
    df2['id'] = 'ID-2'
    df = df.set_index('id', append=True).unstack().reorder_levels([1, 0], axis=1)
    df2 = df2.set_index('id', append=True).unstack().reorder_levels([1, 0], axis=1)
    aggdf = pd.concat([df, df2], axis=1)
    # Start building the pdf
    pdf = PdfBuilder(pdf_path)
    # build the templates to use
    gt = GridTemplate('T1', 100, 100)
    gt.define_frames({
        'HEADER': gt[:10, :],
        'TBL': gt[10:],
    })
    gt.register(pdf)

    # Build the pdf tables to marry with the template
    def make_builder(hdr=1, idx=1, cstyles=None):
        tf = TableFormatter(aggdf, inc_header=hdr, inc_index=idx)
        tf.apply_default_style(index_override={'BACKGROUND': colors.beige})
        tf.header.detect_colspans()
        tf.header.apply_style('ALIGN', 'CENTER')
        tf.cells.match_any_labels('pct').apply_number_format(PercentFormatter)
        tf.cells.match_any_labels('k').apply_number_format(ThousandsFormatter)
        tf.cells.match_any_labels('int').apply_number_format(IntFormatter)
        tf.cells.match_any_labels('M').apply_number_format(MillionsFormatter)
        tf.cells.match_any_labels('$').apply_number_format(DollarCentsFormatter)

        def red_weekend(x):
            if x.dayofweek in (5, 6):
                return dict(BACKGROUND=colors.HexColor("#800000"), TEXTCOLOR=colors.white)

        tf.cells.match_any_labels('date').apply(format=fmt.Y_m_dFormatter, cstyles=red_weekend)
        return tf

    # Build PDF
    for hon, ion in list(itertools.product([True, False], repeat=2)):
        offon = lambda v: v and 'On' or 'Off'
        for cstyle in [None, ConditionalRedBlack]:
            hdr = 'Index=%s Header=%s Color=%s' % (offon(ion), offon(hon), offon(cstyle is not None))
            data = {
                'HEADER': Paragraph(hdr, getSampleStyleSheet()['Normal']),
                'TBL': make_builder(hon, ion, cstyle).build(),
            }
            pdf.build_page('T1', data)
    pdf.save()
    print pdf_path 
Example #20
Source File: report.py    From flask-restful-example with MIT License 5 votes vote down vote up
def pdf_write(generated_pdf_path):
    """
    生成pdf
    :return:
    """
    # 增加的字体,支持中文显示,需要自行下载支持中文的字体
    font_path = current_app.config.get("SIM_SUN")

    pdfmetrics.registerFont(TTFont('SimSun', os.path.join(font_path, 'SimSun.ttf')))
    styles = getSampleStyleSheet()
    styles.add(ParagraphStyle(fontName='SimSun', name='SimSun', leading=20, fontSize=12))
    data = list()
    # 添加一段文字
    paragraph = paragraph_model("测试添加一段文字")
    data.append(paragraph)
    data.append(PageBreak())  # 分页标识
    # 添加table和图片
    table = table_model()
    data.append(table)
    data.append(PageBreak())  # 分页标识
    img = image_model()
    data.append(img)

    # 设置生成pdf的名字和编剧
    pdf = SimpleDocTemplate(generated_pdf_path, rightMargin=0, leftMargin=0, topMargin=40, bottomMargin=0, )
    # 设置pdf每页的大小
    pdf.pagesize = (9 * inch, 10 * inch)

    pdf.multiBuild(data)
    return generated_pdf_path 
Example #21
Source File: test.py    From stdm with GNU General Public License v2.0 4 votes vote down vote up
def run():
    styles = getSampleStyleSheet()
    styleN = styles['Normal']
    styleH = styles['Heading1']
    story = []

    #for codeNames in code
    story.append(Paragraph('I2of5', styleN))
    story.append(I2of5(1234, barWidth = inch*0.02, checksum=0))
    story.append(Paragraph('MSI', styleN))
    story.append(MSI(1234))
    story.append(Paragraph('Codabar', styleN))
    story.append(Codabar("A012345B", barWidth = inch*0.02))
    story.append(Paragraph('Code 11', styleN))
    story.append(Code11("01234545634563"))
    story.append(Paragraph('Code 39', styleN))
    story.append(Standard39("A012345B%R"))
    story.append(Paragraph('Extended Code 39', styleN))
    story.append(Extended39("A012345B}"))
    story.append(Paragraph('Code93', styleN))
    story.append(Standard93("CODE 93"))
    story.append(Paragraph('Extended Code93', styleN))
    story.append(Extended93("L@@K! Code 93 :-)")) #, barWidth=0.005 * inch))
    story.append(Paragraph('Code 128', styleN))
    c=Code128("AB-12345678") #, barWidth=0.005 * inch)
    #print 'WIDTH =', (c.width / inch), 'barWidth =', (c.barWidth / inch)
    #print 'LQ =', (c.lquiet / inch), 'RQ =', (c.rquiet / inch)
    story.append(c)
    story.append(Paragraph('USPS FIM', styleN))
    story.append(FIM("A"))
    story.append(Paragraph('USPS POSTNET', styleN))
    story.append(POSTNET('78247-1043'))
    story.append(Paragraph('USPS 4 State', styleN))
    story.append(USPS_4State('01234567094987654321','01234567891'))

    from reportlab.graphics.barcode import createBarcodeDrawing
    story.append(Paragraph('EAN13', styleN))
    bcd = createBarcodeDrawing('EAN13', value='123456789012')
    story.append(bcd)
    story.append(Paragraph('EAN8', styleN))
    bcd = createBarcodeDrawing('EAN8', value='1234567')
    story.append(bcd)
    story.append(Paragraph('UPCA', styleN))
    bcd = createBarcodeDrawing('UPCA', value='03600029145')
    story.append(bcd)
    story.append(Paragraph('USPS_4State', styleN))
    bcd = createBarcodeDrawing('USPS_4State', value='01234567094987654321',routing='01234567891')
    story.append(bcd)

    story.append(Paragraph('Label Size', styleN))
    story.append(XBox((2.0 + 5.0/8.0)*inch, 1 * inch, '1x2-5/8"'))
    story.append(Paragraph('Label Size', styleN))
    story.append(XBox((1.75)*inch, .5 * inch, '1/2x1-3/4"'))
    c = Canvas('out.pdf')
    f = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1)
    f.addFromList(story, c)
    c.save()
    print 'saved out.pdf' 
Example #22
Source File: test.py    From Fluid-Designer with GNU General Public License v3.0 4 votes vote down vote up
def run():
    styles = getSampleStyleSheet()
    styleN = styles['Normal']
    styleH = styles['Heading1']
    story = []

    #for codeNames in code
    story.append(Paragraph('I2of5', styleN))
    story.append(I2of5(1234, barWidth = inch*0.02, checksum=0))
    story.append(Paragraph('MSI', styleN))
    story.append(MSI(1234))
    story.append(Paragraph('Codabar', styleN))
    story.append(Codabar("A012345B", barWidth = inch*0.02))
    story.append(Paragraph('Code 11', styleN))
    story.append(Code11("01234545634563"))
    story.append(Paragraph('Code 39', styleN))
    story.append(Standard39("A012345B%R"))
    story.append(Paragraph('Extended Code 39', styleN))
    story.append(Extended39("A012345B}"))
    story.append(Paragraph('Code93', styleN))
    story.append(Standard93("CODE 93"))
    story.append(Paragraph('Extended Code93', styleN))
    story.append(Extended93("L@@K! Code 93 :-)")) #, barWidth=0.005 * inch))
    story.append(Paragraph('Code 128', styleN))
    c=Code128("AB-12345678") #, barWidth=0.005 * inch)
    #print 'WIDTH =', (c.width / inch), 'barWidth =', (c.barWidth / inch)
    #print 'LQ =', (c.lquiet / inch), 'RQ =', (c.rquiet / inch)
    story.append(c)
    story.append(Paragraph('USPS FIM', styleN))
    story.append(FIM("A"))
    story.append(Paragraph('USPS POSTNET', styleN))
    story.append(POSTNET('78247-1043'))
    story.append(Paragraph('USPS 4 State', styleN))
    story.append(USPS_4State('01234567094987654321','01234567891'))

    from reportlab.graphics.barcode import createBarcodeDrawing
    story.append(Paragraph('EAN13', styleN))
    bcd = createBarcodeDrawing('EAN13', value='123456789012')
    story.append(bcd)
    story.append(Paragraph('EAN8', styleN))
    bcd = createBarcodeDrawing('EAN8', value='1234567')
    story.append(bcd)
    story.append(Paragraph('UPCA', styleN))
    bcd = createBarcodeDrawing('UPCA', value='03600029145')
    story.append(bcd)
    story.append(Paragraph('USPS_4State', styleN))
    bcd = createBarcodeDrawing('USPS_4State', value='01234567094987654321',routing='01234567891')
    story.append(bcd)

    story.append(Paragraph('Label Size', styleN))
    story.append(XBox((2.0 + 5.0/8.0)*inch, 1 * inch, '1x2-5/8"'))
    story.append(Paragraph('Label Size', styleN))
    story.append(XBox((1.75)*inch, .5 * inch, '1/2x1-3/4"'))
    c = Canvas('out.pdf')
    f = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1)
    f.addFromList(story, c)
    c.save()
    print('saved out.pdf') 
Example #23
Source File: reporting.py    From attack_monitor with GNU General Public License v3.0 4 votes vote down vote up
def pdf_initalize_styles(self):
        self.load_font()
        self.styles = getSampleStyleSheet()

        # ADD CUSTOM STYLES
        self.styles.add(ParagraphStyle(name='subtitle',
                                       parent=self.styles['Normal'],
                                       fontSize=12,
                                       leading=22,
                                       alignment=TA_CENTER,
                                       spaceAfter=6), alias='subtitle',

                        )

        self.styles.add(ParagraphStyle(name='bigtitle',
                                       parent=self.styles['title'],
                                       fontSize=30,
                                       leading=22,
                                       alignment=TA_CENTER,
                                       spaceAfter=6), alias='bigtitle')

        self.styles.add(ParagraphStyle(name='italictitle',
                                   parent=self.styles['Italic'],
                                   fontSize=12,
                                   leading=22,
                                   alignment=TA_CENTER,
                                   spaceAfter=6), alias='italictitle')

        self.styles.add(ParagraphStyle(name="commandline",
                                       parent=self.styles['Italic'],
                                       fontName="freeserif",
                                       fontSize=8,
                                       leading=12,
                                       leftIndent=0,
                                       alignment=TA_RIGHT,
                                       spaceAfter=6),
                        alias="commandline")

        for i in range(0,9):
            style_name = "dynamicindent" + str(i)
            power_factor = 6
            self.styles.add(ParagraphStyle(name=style_name,
                                           parent=self.styles['Normal'],
                                           fontName="freeserif",
                                           fontSize=12,
                                           leading=12,
                                           leftIndent=i*power_factor,
                                           alignment=TA_LEFT,
                                           spaceAfter=6),
                            alias=style_name)