0

I am trying to automatically write reports in python. These reports contain both text and images. Is there a way I could write successively text and put images in a file using python?

martineau
  • 119,623
  • 25
  • 170
  • 301

2 Answers2

1

You could write a HTML file, using Base64 to encode images directly into the <img> tags rather than referring to files elsewhere.

You could use a PDF generation toolkit such as ReportLab.

jasonharper
  • 9,450
  • 2
  • 18
  • 42
1

In the end, the file data is also just plain text. The only problem is how to parse the reports e.g. differ plain text from file data.

You could use the JSON library to parse such reports. Since JSON cannot not deal with raw binary data you might encode the strings to base64 first

data.encode('base64')

Here are some related topics on that problem:

If there are images within the report one could also use HTML as jasonharper suggested:

Nicolas Heimann
  • 2,561
  • 16
  • 27