Comment extraire toutes les images d'un document Word

how to extract all images?

I. Presentation

In this tutorial, we will learn how to extract all the images contained in a Word document. A very practical trick that avoids having to recover the images one by one. A time saver in perspective for people who often need to perform this manipulation on DOCX files. Personally, I regularly use this method when an editor on the site sends me a draft of an article in Word format.

We will see how to do it manually via the Windows graphical interface. For people more comfortable, I will also provide a piece of PowerShell code to do this automatically.

Before you begin, make a copy of the Word file as a precaution.

II. Manual method

First, we need to change the extension of the file, which in this example is called “document.docx”. Right-click “Rename” on the file in File Explorer, or press the “F2” key on the keyboard. Replace the “.docx” extension with “.zip”. If the extension is not visible, you need to configure File Explorer to show it (View > Filename Extensions).

The window “Are you sure you want to modify the extension?” will appear. Click “Oui“.

Word Document - Rename DOCX to ZIP

Next, now that the Word document is in archive format, we will extract the contents of the ZIP. Right-click and click “Extract all…“. A confirmation window appears. Click “Extract“: by default the content will be stored in the same directory as the document with a folder that takes the name of the document.

Extract the contents of a DOCX

Go to the created folder, in my case “Documents”, in order to browse the contents of the archive. The images are located in “Word” then “media” as you can see below:

Recover images from a Word DOCX

Here, you have just recovered all the images of your Word document! You can change the document extension again to “.docx” or simply delete this version if you have made a copy beforehand.

III. Automatic method with PowerShell

For scripting people, you can create a script that will extract the contents of the Word file.

Here is the contents of the file “Extract-ImagesFromWord.ps1” :

param([ValidateScript({Test-Path $_})]$File)

Rename-Item -Path $File -NewName "$File.zip"
if(Test-Path -Path "$File.zip"){
    Expand-Archive -Path "$File.zip" -DestinationPath "C:\TEMP\ImagesWord"
    Rename-Item -Path "$File.zip" -NewName $File
}

This piece of code will take the trouble to rename the file, extract the contents, then put back the original extension of the file. Then, we will execute it like this:

.\Extract-ImagesFromWord.ps1 -File "C:\temp\Document.docx"

However, it can be done much simpler by using only the “Expand-Archive” command because PowerShell will be able to extract the contents of the document, no matter if it is in DOCX or ZIP. When using Windows File Explorer, you must rename the document so that the “Extract All” option is offered.

So the command below, to run in a PowerShell consolewill extract the contents of the DOCX on the same principle as the command in graphical mode:

Expand-Archive .\Document.docx

Even faster and more convenient than with File Explorer!

Astuces,Logiciels,Powershell,Astuce,Word,

#extract #images

Leave a Comment

Your email address will not be published. Required fields are marked *