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
Notifications You must be signed in to change notification settings
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go to fileThis library allows you to quickly convert Microsoft Word documents to image through msword2image.com using PHP for free!
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?"
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
$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.
$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromURL('http://mswordtoimage.com/docs/demo.doc'); $base64String = $convert->toBase46EncodedString(); echo "";
$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.
$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo.doc'); $base64String = $convert->toBase46EncodedString(); echo ""; // Please make sure input file is readable by your PHP process.
$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.
$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.
$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.
$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.
$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.
Input\Output | PNG | GIF | JPEG | Page count |
DOC | ✔ | ✔ | ✔ | ✔ |
DOCX | ✔ | ✔ | ✔ | ✔ |