Learn how to extract images from Word documents in Python: https://blog.aspose.com/2021/11/19/extract-images-from-word-in-python/
Last active
November 19, 2021 14:17
-
-
Save aspose-com-gists/541ef80e756af284d3827cd04466b53f to your computer and use it in GitHub Desktop.
Extract Images from Word Document in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.words as aw | |
# load the Word document | |
doc = aw.Document("calibre.docx") | |
# retrieve all shapes | |
shapes = doc.get_child_nodes(aw.NodeType.SHAPE, True) | |
imageIndex = 0 | |
# loop through shapes | |
for shape in shapes : | |
shape = shape.as_shape() | |
if (shape.has_image) : | |
# set image file's name | |
imageFileName = f"Image.ExportImages.{imageIndex}_{aw.FileFormatUtil.image_type_to_extension(shape.image_data.image_type)}" | |
# save image | |
shape.image_data.save(imageFileName) | |
imageIndex += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment