Git Product home page Git Product logo

msword2image-php's Introduction

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 "<img src='data:image/jpeg;base64,$base64String' />";

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 "<img src='data:image/jpeg;base64,$base64String' />";
// 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 "<img src='data:image/gif;base64,$base64String' />";
// 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 "<img src='data:image/png;base64,$base64String' />";
// 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 "<img src='data:image/jpeg;base64,$base64String' />";
// 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

msword2image-php's People

Contributors

mertdeg2 avatar msword2image avatar

Watchers

James Cloos avatar Tirapong Chaiyakun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.