Convert text to an image in Python using Aspose.Words

In this tutorial, we are going to see how to convert text to an image in Python. This can be easily done by using the Aspose.Words library. This library is used to process documents in Python. You can work with different types of documents like pdf, text, images, etc. using Aspose.Words.

First of all, install the library using the following command:

pip install aspose-words

Now import the library to use in the code.

import aspose.words as aw

Note: Type the text you wish to convert into an image in a text file. Save that file with the extension .text/.txt
input text file

Now using the Document() function from Aspose.Words library access the previously created text document. This function takes the document file path as an argument.

doc = aw.Document('input_text.txt')


extract_pages(0,1) is the method from Aspose.Words library which extracts the pages between specified ranges from the document.
0 is the starting page index. And 1 is the maximum number of pages to be selected next starting from the starting index. You can vary indices if your document has multiple pages.

Now using this function extract the text file pages. And save it as an image using the save() method. The image will get saved into your current directory.

extracted_pages = doc.extract_pages(0,1)"output_image.jpg")


Text to image in Python using Aspose.Words

Also, refer to Convert base64 string to Image in Python

Leave a Reply

Your email address will not be published. Required fields are marked *