2

I have a question about generating Rich Text output in Python. I had a decent amount of experience processing data with Python and writing to .csv/.txt files for opening in Excel.

I'm working on a project to generate a patient report from a Python program that has stripped all the diagnoses/items of interest out of a database. Basically, I have a list of diagnoses and currently just write it to a .txt file with no formatting. Ideally, the program will apply formatting to the text (e.g. diagnoses are in bold, criteria for each diagnosis is a bullet point under the bold point). The gold standard would be if I could somehow create a PDF of the report w/ headers and footers as well.

Any ideas on how this could be possible? Is Python blatantly the wrong choice for this?

2
  • 1
    It probably wouldn't be hard to write your own rudimentary RTF exporter: en.wikipedia.org/wiki/Rich_Text_Format Commented Nov 8, 2018 at 21:16
  • 1
    The accepted answer is for creating a PDF, so it would be good to change the title to creating a PDF. Because the answer brings no info to someone who actually wants to create a RTF and not a PDF. Commented Mar 28, 2022 at 16:40

1 Answer 1

2

Check out PyPDF for creating nicely formatted PDF files with Python: https://www.blog.pythonlibrary.org/2018/06/05/creating-pdfs-with-pyfpdf-and-python/

Here's a simple demo of how you could use the package to create a pdf:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.set_font("Helvetica", size=12)
pdf.cell(200, 10, txt="HEADER", ln=0, align="C")
pdf.cell(0, 10, txt="11/8/18", ln=0, align="R")
pdf.output("example.pdf")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.