Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Extract Images from Word Document in Python
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
imageIndex += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment