I’m using reportlab, and I think the image is causing the problem, triggering this error: ‘AttributeError: ‘list’ object has no attribute ‘getKeepWithNext’.’ I’m trying to center the header_text and header2, align the mainlogo to the left, and position the otherlogo to the right. How can I achieve this?”
def generate_pdf(employee_data, output_file):
doc = SimpleDocTemplate(output_file, pagesize=letter, topMargin=20)
elements = []
header_text = "C O M P A N Y N A M E"
header2 = "Employee Reports List"
styles = getSampleStyleSheet()
header_style = styles["Heading1"]
header_style.alignment = 1
header_style.spaceBefore = 0
logo_left = "mainlogo.png"
logo_right = "otherlogo.jpg"
left_logo = Image(logo_left, width=50, height=50)
right_logo = Image(logo_right, width=50, height=50)
header_content = [[left_logo, Paragraph(header_text, header_style), right_logo]]
header2text = Paragraph(header2, header_style)
# append to the header
elements.extend(header_content)
elements.append(header2text)
elements.append(Spacer(1, 12))
data = [['Employee Name', 'Mobile No', 'Address']]
data.append(['--------------------', '--------------------', '----------------------------------------------------------------------------------------------']) # Separator line
for employee in employee_data:
# Adjust the width of the Address column
# You can adjust the width as per your requirement
# For example, setting a width of 200 for the Address column
data.append([employee[0], employee[2][:200], employee[1]])
style = TableStyle([('FONT', (0, 0), (-1, 0), 'Helvetica-Bold'),
('BACKGROUND', (0, 0), (-1, 0), colors.white),])
table = Table(data)
table.setStyle(style)
elements.append(table)
# Build PDF
doc.build(elements)