Saved searches

Use saved searches to filter your results more quickly

Cancel Create saved search Sign up Reseting focus

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Programatically Convert Microsoft Word Documents to Image - PHP

License

Notifications You must be signed in to change notification settings

msword2image/msword2image-php

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Go to file

Folders and files

Last commit message Last commit date

Latest commit

History

View all files

Repository files navigation

MSWord2Image-PHP

This library allows you to quickly convert Microsoft Word documents to image through msword2image.com using PHP for free!

Demo

Example conversion: From demo.docx to output.png. Note that you can try this out by visting msword2image.com and clicking "Want to convert just one?"

Installation

You can simply download this github repo as a zip file. Extract contents and include MsWordToImageConvert.php

require_once 'lib/MsWordToImageConvert.php';
Note: Please make sure cURL is enabled with your PHP installation

Usage

1. Convert from Word document URL to JPEG file

$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromURL('http://mswordtoimage.com/docs/demo.doc'); $convert->toFile('demo.jpeg'); // Please make sure output file is writable by your PHP process.

2. Convert from Word document URL to base 64 JPEG string

$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromURL('http://mswordtoimage.com/docs/demo.doc'); $base64String = $convert->toBase46EncodedString(); echo "";

3. Convert from Word file to JPEG file

$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo.doc'); $convert->toFile('demo.jpeg'); // Please make sure output file is writable and input file is readable by your PHP process.

4. Convert from Word file to base 64 encoded JPEG string

$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo.doc'); $base64String = $convert->toBase46EncodedString(); echo ""; // Please make sure input file is readable by your PHP process.

5. Convert from Word file to base 64 encoded GIF string

$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo.doc'); $base64String = $convert->toBase46EncodedString(\MsWordToImageConvert\OutputImageFormat::GIF); echo ""; // Please make sure input file is readable by your PHP process.

6. Convert from Word file to base 64 encoded PNG string

$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo.doc'); $base64String = $convert->toBase46EncodedString(\MsWordToImageConvert\OutputImageFormat::JPEG); echo ""; // Please make sure input file is readable by your PHP process.

7. Get the page count of a given Word file

$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo2.doc'); $toPageCount = $convert->toPageCount(); // $toPageCount will be integer representing the page count in the word file // Please make sure input file is readable by your PHP process.

8. Get the page count of a given Word file URL

$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('http://msword2image.com/docs/demo2.doc'); $toPageCount = $convert->toPageCount(); // $toPageCount should be 5 // Please make sure input file is readable by your PHP process.

9. Get the specific page of a Word document as image

$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo2.doc'); $base64String = $convert->toBase46EncodedString( \MsWordToImageConvert\OutputImageFormat::JPEG, 2 ); echo ""; // Note that pages are 0-indexed. Above code will print the third page of word document // Please make sure input file is readable by your PHP process.

Supported file formats

Input\Output PNG GIF JPEG Page count
DOC
DOCX