Word to PNG JPEG BMP using Python

The conversion of MS Word files to image formats lets you embed the document’s pages into your web or desktop applications. In order to perform this conversion from within the Python applications, this article covers how to convert Word DOCX or DOC files to PNG, JPEG, or BMP images using Python. Moreover, you will learn how to control the Word to image conversion using different options.

Python API for Word to Image Conversion

To convert Word documents to PNG. JPEG, or BMP images, we will use Aspose.Words for Python. It is a powerful Python library to create, process, and convert MS Word documents. Aspose.Words for Python is available on PyPI and you can install it using the following pip command.

pip install aspose-words

Convert a Word Document to PNG, JPEG, or BMP in Python

It is quite easier to convert a Word document to popular images formats using Aspose.Words for Python. You can opt for the desired output image format from PNG, JPEG, and BMP. The following are the steps to convert a Word document to a PNG image using Python.

  • Load the Word document using Document class.
  • Specify the output image format using ImageSaveOptions class.
  • Loop through the page count in the document.
  • Convert each page in Word document to PNG image using Document.save(string, ImageSaveOptions) method.

The following code sample shows how to convert a Word document to PNG images in Python.

Control Word to Image Conversion in Python

You can also control the Word to image conversion using different options. For example, you can set horizontal resolution, vertical resolution, overall resolution, scale, pixel format, brightness, color mode, contrast, and paper color. The following are the steps to use the above-mentioned features in Word to image conversion using Python.

  • Load the Word document using Document class.
  • Specify the output image format using ImageSaveOptions class.
  • Set desired options such as ImageSaveOptions.image_brightness, ImageSaveOptions.image_brightness, etc.
  • Loop through the page count in the document.
  • Convert each page to image using Document.save(string, ImageSaveOptions) method.

The following code sample shows how to control Word to JPEG image conversion using different options.

Get a Free API License

You can get a temporary license in order to use Aspose.Words for Python without evaluation limitations.

Conclusion

In this article, you have learned how to convert Word documents to PNG, JPEG, or BMP images using Python. Moreover, you have seen how to control Word to image conversion using different options. Apart from that, you can explore other features offered by Aspose.Words for Python using the documentation. Also, you can post your questions on our forum.

See Also

Info: You may be interested in another Python API (Aspose.Slides for Python via NET) that allows you to convert presentations to images and import images into presentations.