Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active November 19, 2021 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/541ef80e756af284d3827cd04466b53f to your computer and use it in GitHub Desktop.
Save aspose-com-gists/541ef80e756af284d3827cd04466b53f to your computer and use it in GitHub Desktop.
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
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