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?
Asked
Active
Viewed 219 times
0
-
I 'd suggest taking a look at jupyter notebooks. – May 26 '17 at 16:24
-
I'll check if I can export a jupyter notebook to a pdf file – Quentin Brzustowski May 29 '17 at 06:38
2 Answers
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:
How to include pictures bytes to a JSON with python? (encoding issue)
how to serialize arbitrary file types to json string in python
If there are images within the report one could also use HTML as jasonharper suggested:

Nicolas Heimann
- 2,561
- 16
- 27