So I'm creating a streamlit
web app where people provide a paragraph and I split it up into sentences and allow them to download it as a PDF after applying color-blind friendly color coding. To do this, I create HTML and add the color coding as a style attribute. I then try and download it using fpdf2
. However, when I open the downloaded PDF, there is no color.
class PDF(FPDF, HTMLMixin):
pass
def create_html(text, hex_codes):
result = nltk.sent_tokenize(text)
hex1 = hex_codes[0]
hex2 = hex_codes[1]
flag = True
res = []
for sentence in result:
if flag:
hex = hex1
else:
hex = hex2
flag = not flag
res.append(f"<p style ='color:{hex}'>{sentence}</p>")
return ''.join(res)
def create_pdf(html):
pdf = PDF()
pdf.add_page()
pdf.write_html(html)
return BytesIO(pdf.output())
Is there any reason this happens?