Please follow the tutorial https://roytuts.com/how-to-convert-file-content-into-pdf-document-using-python/