0

My need is to get an image of the text in a word file using Python. The text length changes with every file. How can I detect the text and take a screenshot or generate an image of that text without including the whitespace from the rest of the document? The text can span multiple lines.

Here is an example of the word file

And this is the result I am looking for

I'm writing a script that reads the word file, takes a screenshot as above, and then saves it to a location.

EDIT: SOLVED.

1 Answers1

0

To extract the text you could use any of the many solutions listed here

After that to create a new image, you can use PIL, here some more examples https://notebooks.ai/santiagobasulto/how-to-generate-images-with-text-using-python-and-pil-bcd5d188 https://code-maven.com/create-images-with-python-pil-pillow

Fin
  • 19
  • 3
  • I should add that there can be equations as well, so reading those as a text will change the format. Is there any way to detect text and take a screenshot. – Harshit Saini Apr 18 '21 at 10:47