Converting between Word Doc and HTML is a very important conversion for a number of reasons. As it will allow you to turn an existing Word document into an HTML page, this will eliminate the risk of losing or editing any document content. With this conversion, you no longer need to worry about downloading documents and having them in a single location, you can access them from any device (mobile phones, tablets, computers), on any platform, with no extra software.

First, we need to have a look at the API tool we’re using, for this tutorial, we will be using Doc Conversion API, A REST API For easily converting document formats, as it allows you to convert between Word, Excel, PowerPoint, HTML, PDF and different image formats with a whole bunch of sensible formatting options.

Prerequisites

Before we start with this tutorial, we need to prepare a few simple prerequisites. We need have an account with Doc Conversion API, so we can use our app credentials in the REST request.

To create your account, you can sign up here for free. You will then be able to login to your dashboard, from there, you will need to take note of two keys that will play an important role in this tutorial, your Application ID, and your Secret Key.

To get these credentials:

  1. Click on API Applications
  2. You will see a list of your applications, select the one you would like to use and take note of these two values. (For this tutorial, we’re using the default application, which is automatically created for you you first sign up).

Using the REST API

Doc Conversion API have an API that you can easily connect to and integrate with your service, code or apps. We’re first going to test the connection with the API by retrieving the connection status of the service.

For this PHP example, we’re using a direct URL for our word document (the document we’re converting) for simplicity, you can also upload documents to the service.

We’re going to be using this example:

http://homepages.inf.ed.ac.uk/neilb/TestWordDoc.doc

We’re going to create a simple PHP page that reads the Doc file from a URL, and converts this file into an HTML page:

Download this page / View this page

This code will execute the conversion, and display the Word Doc content as an HTML page.

You can follow the same steps with different formats conversions as Doc Conversion API offers an extensive list of conversions that you can easily implement.

You can find a list of different format conversion APIs and more examples here.

✉️ Subscribe to CodeBurst’s once-weekly Email Blast, 🐦 Follow CodeBurst on Twitter, view 🗺️ The 2018 Web Developer Roadmap, and 🕸️ Learn Full Stack Web Development.