'Reportlab pyhton alignment issue

enter image description here

Style3 = TableStyle([('VALIGN',(0,0),(-1,-1),'TOP'), ('ALIGN',(0,0),(-1,-1),'RIGHT'), ('LEFTPADDING',(0,0),(-1,-1), 130), ('RIGHTPADDING',(0,0),(-1,-1), 0), ('TOPPADDING',(0,0),(-1,-1), 0), ])

I want response and categories label in starting but it show at the end of line, i want response and categories in from starting not end of line..

any special styling i need.

def getToolsTables(data,tname): doc = SimpleDocTemplate("somefilename.pdf",pagesize=A2, topMargin=25, bottomMargin=0) main_header = [] h_arr1 = [] h_arr1.append(tname) main_header.append(h_arr1) mainHeader = Table(main_header, colWidths='*')

finalTable = []

main_table_header_Style = TableStyle([
    ('BACKGROUND', (0, 0), (-1, 0), '#D3D3D3'),
    ('TEXTCOLOR',(0,0),(-1,-1),colors.black),
    ('ALIGN',(0,0),(-1,-1),'LEFT'),
    ('FONTSIZE', (0,0), (-1,-1), 12),
    ('FONTNAME', (0,0), (-1,-1), 
        'Courier-Bold'
        ), 

    ('TOPPADDING',(0,0),(-1,-1), 5),
    ('BOTTOMPADDING',(0,0),(-1,-1), 7), 
    ('LINEBELOW',(0,0),(-1,0),1,colors.black)
    ])

tools_table_header_Style = TableStyle([
    ('BACKGROUND', (0, 0), (-1, 0), 'lightblue'),
    ('TEXTCOLOR',(0,0),(-1,-1),colors.black),
    ('ALIGN',(0,0),(-1,-1),'LEFT'),
    ('FONTSIZE', (0,0), (-1,-1), 11),
    ('FONTNAME', (0,0), (-1,-1), 
        'Courier-Bold'),
    ])

tools_table_header_Style1 = TableStyle([
    ('BACKGROUND', (0, 0), (-1, 0), 'lightgreen'),
    ('TEXTCOLOR',(0,0),(-1,-1),colors.black),
    ('ALIGN',(0,0),(-1,-1),'CENTER'),
    ('FONTSIZE', (0,0), (-1,-1), 11),
    ('FONTNAME', (0,0), (-1,-1), 
        'Courier-Bold'),
    ])

Style2 = TableStyle([        
                    ('ALIGN',(0,0),(-1,-1),'LEFT'),
                    ('LEFTPADDING',(0,0),(-1,-1), 0),
                    ('RIGHTPADDING',(0,0),(-1,-1), 0),
                    ('BOTTOMPADDING',(0,0),(-1,-1), -10),])



Style3 = TableStyle([('VALIGN',(0,0),(-1,-1),'TOP'),
                    ('ALIGN',(0,0),(-1,-1),'RIGHT'),
                    ('LEFTPADDING',(0,0),(-1,-1), 130),
                    ('RIGHTPADDING',(0,0),(-1,-1), 0),
                    ('TOPPADDING',(0,0),(-1,-1), 0),
                    ])


mainHeader.setStyle(main_table_header_Style) # adding style to table main header
finalTable.append(mainHeader)

# Create Tools Array 
tools_header = []
tools_body = []

# print(',,,,,,,,,,,,,,,,,,,,,,,,',data)
if type(data) == dict:
    all_table = []
    for key, value in data.items() :
        temp = []
        temp_table = []
        temp.append(key)
        tool_table_header = Table([temp],colWidths='*')
        tool_table_header.setStyle(tools_table_header_Style)
        temp_table.append(tool_table_header)
        
        if key != 'Builtwith':
            t_h = []
            t_b = []
            for k,v in value.items():
                t_h.append(k)
                t_b.append(v)

            t_body = []
            # import pdb; pdb.set_trace()
            for index, item in enumerate(t_h):
                if item != 'status':
                    arr1 = []
                    arr2 = []
                    if type(t_b[index]) is list:
                        temp_txt = ''
                        for txt in t_b[index]:
                            temp_txt += txt + ',  '
                        arr1.append(item + ':')
                        text = t_b[index]
                        wraped_text = "\n".join(wrap(str(temp_txt[:-3]), 60)) # 60 is line width
                        arr1.append(wraped_text)

                    else:
                        arr1.append(item + ':')
                        text = t_b[index]
                        

                        wraped_text = "\n".join(wrap(str(text), 60)) # 60 is line width
                        arr1.append(wraped_text)


                    arr2.append(arr1)
                    n_table =Table(arr2,[200,370])
                    t_body.append(n_table)

                
            tool_header = Table([temp_table], colWidths='*')
            tool_body = Table([[t_body]],[200,370])
            finalTable.append(Table([[[tool_header,tool_body]]], colWidths='*'))

        else:
            for key,val in value.items():
                temp1 = []
                temp_table1 = []
                temp1.append(key)
                tool_table_header = Table([temp1],colWidths='*')
                tool_table_header.setStyle(tools_table_header_Style1)
                temp_table1.append(tool_table_header)
                print('kkkkkkkk')


                t_h = []
                t_b = []
                for k,v in val.items():
                    t_h.append(k)
                    t_b.append(v)

                t_body = []
                for index, item in enumerate(t_h):
                    if item != 'status':
                        arr1 = []
                        arr2 = []
                        if type(t_b[index]) is list:
                            temp_txt = ''
                            for txt in t_b[index]:
                                temp_txt += txt + ',  '
                            arr1.append(item + ':')
                            text = t_b[index]
                            wraped_text = "\n".join(wrap(str(temp_txt[:-3]), 60)) # 60 is line width
                            arr1.append(wraped_text)
                        else:
                            arr1.append(item + ':')
                            text = t_b[index]
                            wraped_text = "\n".join(wrap(str(text), 80)) # 60 is line width
                            arr1.append(wraped_text)


                        arr2.append(arr1)
                        n_table =Table(arr2,[200,370])
                        t_body.append(n_table)

                    
            tool_header = Table([temp_table1], colWidths='*')
            tool_header.setStyle(Style3)
            tool_body = Table([[t_body]],[200,370])

            table = Table([[[temp_table,tool_header,tool_body]]],colWidths='*')
            finalTable.append(table)


else:
    # finalTable.append(Table([['Tools Scan in progress...']], colWidths='*'))
    finalTable.append(Table([[data]], colWidths='*'))


return finalTable


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source