Exemple #1
0
    def add_header(self, my_canvas):
        #File info
        # my_canvas = Canvas("frame_demo.pdf", pagesize=letter, bottomup = 1)
        page_width, page_height = letter  #keep for later
        styles = getSampleStyleSheet()
        normal = styles['Normal']
        normal.alignment = TA_LEFT
        centered_heading = styles['Heading1']
        centered_heading.alignment = TA_CENTER
        centered_normal = styles['Normal']
        centered_normal.alignment = TA_CENTER
        heading = styles['Heading1']

        #Information about the content
        title = "Reporte Semanal"
        author = "Gerardo Olmos"
        email = "*****@*****.**"
        formatted_time = time.ctime()

        #Frames - header
        left_frame = Frame(inch,
                           8 * inch,
                           width=2 * inch,
                           height=1.5 * inch,
                           showBoundary=0)
        center_frame = Frame(3 * inch,
                             8 * inch,
                             width=2.5 * inch,
                             height=1.5 * inch,
                             showBoundary=0)
        right_frame = Frame(5.5 * inch,
                            8 * inch,
                            width=2 * inch,
                            height=1.5 * inch,
                            showBoundary=0)

        #Flowable lists
        left_flowables = []
        center_flowables = []
        right_flowables = []

        #Header Logos
        logo_carat = "Reports/imgs/carat_logo.png"
        logo_amplifi = "Reports/imgs/amplifi_logo.png"

        img = utils.ImageReader(logo_carat)
        img_width, img_height = img.getSize()
        desired_width = 1 * inch
        aspect = img_height / float(img_width)
        img = Image(logo_carat,
                    width=desired_width,
                    height=(desired_width * aspect))
        left_flowables.append(img)

        left_flowables.append(Spacer(1, 0.1 * inch))

        img = utils.ImageReader(logo_amplifi)
        img_width, img_height = img.getSize()
        desired_width = 1 * inch
        aspect = img_height / float(img_width)
        img = Image(logo_amplifi,
                    width=desired_width,
                    height=(desired_width * aspect))
        left_flowables.append(img)
        left_flowables.append(Spacer(1, 0.1 * inch))

        # Paragraphs
        left_flowables.append(Paragraph(author, normal))
        normal.fontSize = 8
        left_flowables.append(Paragraph(email, normal))
        normal.fontSize = 10
        center_flowables.append(Paragraph(title, centered_heading))
        right_flowables.append(Paragraph(formatted_time, centered_normal))

        # Add from lists
        left_frame.addFromList(left_flowables, my_canvas)
        center_frame.addFromList(center_flowables, my_canvas)
        right_frame.addFromList(right_flowables, my_canvas)
Exemple #2
0
    def add_client_share(self, canvas, img_path, table_path, title):
        #File info
        page_width, page_height = letter  #keep for later
        styles = getSampleStyleSheet()
        normal = styles['Normal']
        normal.alignment = TA_LEFT
        centered_heading = styles['Heading1']
        centered_heading.alignment = TA_CENTER
        centered_normal = styles['Normal']
        centered_normal.alignment = TA_CENTER
        heading = styles['Heading1']

        # Frames & flowables
        top_frame = Frame(inch,
                          7.5 * inch,
                          width=1.5 * inch,
                          height=0.5 * inch,
                          showBoundary=1)
        left_frame = Frame(inch,
                           3.5 * inch,
                           width=3 * inch,
                           height=4 * inch,
                           showBoundary=1)
        right_frame = Frame(4 * inch,
                            3.5 * inch,
                            width=4 * inch,
                            height=4 * inch,
                            showBoundary=1)
        #TODO center vertical
        top_flowables = []
        left_flowables = []
        right_flowables = []

        # Brief
        # get_brief()
        title = title
        brief_text = "Quien hace tanta bulla y ni deja."
        top_flowables.append(Paragraph(title, normal))

        # Chart
        img = utils.ImageReader(img_path)
        img_width, img_height = img.getSize()
        desired_width = 3.9 * inch
        aspect = img_height / float(img_width)
        img = Image(img_path,
                    width=desired_width,
                    height=(desired_width * aspect))
        right_flowables.append(img)

        # Table
        img = utils.ImageReader(table_path)
        img_width, img_height = img.getSize()
        desired_width = 2.9 * inch
        aspect = img_height / float(img_width)
        img = Image(table_path,
                    width=desired_width,
                    height=(desired_width * aspect))
        left_flowables.append(Spacer(1, 0.1 * inch))
        left_flowables.append(img)

        # Add from lists
        top_frame.addFromList(top_flowables, canvas)
        left_frame.addFromList(left_flowables, canvas)
        right_frame.addFromList(right_flowables, canvas)