Easiest way to extract images from a MS Word Document using PHP?

extract images from word document online
extract background image from word document
extract images from word document python
vba extract images from word document
how to save a picture from a word document to jpeg
how to save a picture from a word document on mac
how to get images from word file
how to save a picture from word 2007

Is this possible to extract images from MS Word Documents using PHP? And if so, how?

Requirement: Definitely old-shool doc support, but preferably both old and new.

Create a new PHP file and name it as extract.php and add the following code in it.


/*Name of the document file*/
$document = 'attractive_prices.docx';

/*Function to extract images*/ 
function readZippedImages($filename) {

/*Create a new ZIP archive object*/
    $zip = new ZipArchive;

    /*Open the received archive file*/
    if (true === $zip->open($filename)) {
        for ($i=0; $i<$zip->numFiles;$i++) {

/*Loop via all the files to check for image files*/
            $zip_element = $zip->statIndex($i);

/*Check for images*/
            if(preg_match("([^\s]+(\.(?i)(jpg|jpeg|png|gif|bmp))$)",$zip_element['name'])) {

/*Display images if present by using display.php*/
                echo "<image src='display.php?filename=".$filename."&index=".$i."' /><hr />";

Now create another PHP file and name it as display.php and add the following code to it.


/*Tell the browser that we want to display an image*/
    header('Content-Type: image/jpeg');

/*Create a new ZIP archive object*/
    $zip = new ZipArchive;

    /*Open the received archive file*/
    if (true === $zip->open($_GET['filename'])) {

/*Get the content of the specified index of ZIP archive*/
        echo $zip->getFromIndex($_GET['index']);


Source(s): Extracting Images from DocX using PHP

Extract Images From A Word Document The Easy Way, Microsoft Word is one of the most common word processors on the market, but while it's a great solution for editing text, managing images� Follow the steps below in order to extract images from a word document the easy way. Extract Images from Word Document. Step 1. You’ll need some sort of file extraction software. In this guide, we’ll be using 7zip since it is free and widely available, but you can use whatever program you’re most comfortable with.

If you are extracting images from older files you have a couple of options.

Run a converter to update all files to DocX then use IntermediateHacker's code.

Find the VBA code necessary to extract the images, and then either create a macro and call this code via PHP's COM interface functions or call the code yourself via these functions.

The first thing to do though is find how to do it in VBA, that will make it much easier to do it in PHP.

How to Extract and Save Images from a Word Document, A quick and easy way to save all the images from Microsoft Word (.docx) file in full Duration: 1:48 Posted: 31 Aug 2015 To extract embedded images from a Word document save the document as a web page using the following steps: 1. On the File menu click Save as Web Page 2. In the Save As drop down select Web Page (*.htm; *.html) Images will be extracted from the document and placed in the folder named <DocumentName>_files in the same location as the saved web page.

If you are using the newer docx format it can easily be achieved because they are no more than a zip file. See the following link:


Tip of the Week: Export Images from Word Files, This InDesign tip was sent to Tip of the Week email subscribers on April original high-resolution images when you place a DOCX file, even if� Method #1: Save the Word document as a Web page. This is the easiest method to extract batch images from a word file, without requiring any special tools. Open the Word document from which you would like to extract images. Now, click on main menu located at the top left corner of the window.

Hope this help You and you can also format according to your need .

 * Created by PhpStorm.
 * User: khalid
 * Date: 04/26/2015
 * Time: 10:32 AM
class DocxImages {
private $file;
private $indexes = [ ];
/** Local directory name where images will be saved */
private $savepath = 'docimages';
public function __construct( $filePath ) {
    $this->file = $filePath;
function extractImages() {
    $ZipArchive = new ZipArchive;
    if ( true === $ZipArchive->open( $this->file ) ) {
        for ( $i = 0; $i < $ZipArchive->numFiles; $i ++ ) {
            $zip_element = $ZipArchive->statIndex( $i );
            if ( preg_match( "([^\s]+(\.(?i)(jpg|jpeg|png|gif|bmp))$)", $zip_element['name'] ) ) {
                $imagename                   = explode( '/', $zip_element['name'] );
                $imagename                   = end( $imagename );
                $this->indexes[ $imagename ] = $i;
function saveAllImages() {
    if ( count( $this->indexes ) == 0 ) {
        echo 'No images found';
    foreach ( $this->indexes as $key => $index ) {
        $zip = new ZipArchive;
        if ( true === $zip->open( $this->file ) ) {
            file_put_contents( dirname( __FILE__ ) . '/' . $this->savepath . '/' .    $key, $zip->getFromIndex( $index ) );
function displayImages() {
    if ( count( $this->indexes ) == 0 ) {
        return 'No images found';
    $images = '';
    foreach ( $this->indexes as $key => $index ) {
        $path = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $this->savepath . '/' . $key;
        $images .= '<img src="' . $path . '" alt="' . $key . '"/> <br>';
    echo $images;
$DocxImages = new DocxImages( "doc.docx" );
/** It will save and display images*/
/** It will only save images to local server */

How to Extract Text & Images Easily from MS Office Files, Well, we have a simple trick to help you extract images and text from files of the Note: For the purpose of demonstrating this post, we will be using only an MS Word file. How to Extract Images & Text from DOCX, PPTX, XLXS Files If you want to extract images from MS office files with older formats, the� Microsoft Word needs no formal introduction. Most often at times, people tend to send documents in Microsoft word format. Usually, the extension for a document file is .doc. So usually, when a .doc file is sent to you, Microsoft word can be used in opening such document.

Top 3 ways to extract , Top 3 ways to extract original image files from a Word document (docx or doc). Main topics are: Nginx, PHP, MySQL, and Windows. This tutorial shows the way, it works with Microsoft Word 2007 and above. Renaming the .docx to .zip, opening the zip file and extracting the images (Best way!) Copying� How to Convert JPG Photos to Editable MS Word File Without Using Any Software - Duration: 1:37. Easy way to extract images from a Word document - Duration: 1:48.

how to convert word document to text file in php, However, if you just want to extract the text in the document, simpler approaches it is time to learn the simple steps for converting the image file into a word document. I want to convert the text data file into ms word document using PHP . Creating Microsoft Word documents in PHP can be a challenge. In this article we will take a closer look at PHPWord and three different ways to create Word documents with it – from building it from scratch to going crazy and merge pre-existing templates with self-created files!

PHPOffice/PHPWord: A pure PHP library for reading and , A pure PHP library for reading and writing word processing documents - PHPOffice/PHPWord. PHPWord is a library written in pure PHP that provides a set of classes to Microsoft Office Open XML (OOXML or OpenXML), OASIS Open Document Insert text breaks and page breaks; Insert and format images, either local,� In today’s post, we want to share with you 2 quick ways to extract individual pages from your Word document. Sometimes in a Word document, each page may contain quite independent contents, such as a table. And you will probably need to send different tables to different people.

  • Yes.... by writing code? What type of doc file are you talking about? Old-school .doc, or modern-ish .docx? It's far far easier with .docx since it's just really a pile of zipped up xml and other stuff.
  • so is hte solution to conver to docx and use this?
  • Or you convert to RTF and extract the images from RTF. But you should write in your question which DOC files and version you're dealing with.
  • your not going to make yourself any friends @RD