I'm creating a PDF using reportlab (in conjunction with Django). I have created the following code for creating a table with heads and details:
elements = []
datas = []
course_info = [
['Course Code' , c.course_code] ,
['Course Title' , c.course_name],
['Prerequisites by Course(s) and Topics', c.pre_reqs],
['Assessment Instruments with Weights (some desc)', c.grade_distribution]
]
for k in course_info:
headpara = Paragraph(k[0], styleB)
datas.append([headpara , Paragraph(clean_string(k[1]), styleN)])
t = LongTable(datas, colWidths=[5 * cm, 12 * cm])
t.setStyle(TableStyle(org.getTableStyle()))
elements.append(t)
doc.build(elements)
I'm using BaseDocTemplate as my template. What I want is to be able to give parts of the headpara as non-bold e.g. the (some desc) part in the fourth row need to be normal style instead of bold. How can I achieve this?
Reportlab supports simple HTML formatting so we can use styleN and make the required text bold. Like so:
course_info = [
['<b>Course Code</b>' , c.course_code] ,
['<b>Course Title</b>' , c.course_name],
['<b>Prerequisites by Course(s) and Topics</b>', c.pre_reqs],
['<b>Assessment Instruments with Weights</b> (some desc)', c.grade_distribution]
]
for k in course_info:
headpara = Paragraph(k[0], styleN)
datas.append([headpara , Paragraph(clean_string(k[1]), styleN)])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With