I am trying to extract the pictures from the header of a word document. But it doesn’t seems to always work. I would like to know if there was a way to get them 100% of the time, thank you ( i am using aspose word python). Here is my code to extract all pictures from a document :
image_index =1
for node in doc.get_child_nodes(aw.NodeType.ANY, True):
if node.node_type == aw.NodeType.SHAPE or node.node_type == aw.NodeType.GROUP_SHAPE:
image_file_name = image_recup(node, image_index)
image_index += 1
and here is function image_recup :
def image_recup(node, image_index):
# Créer un dossier pour enregistrer les images
if not os.path.exists("images"):
os.makedirs("images")
# Enregistrer l'image dans le dossier avec un nom unique
image_file_name = f"images/image_{image_index}.png"
node.as_shape().image_data.save(image_file_name)
with Image.open(image_file_name) as img:
img.save(image_file_name)
return image_file_name