
You can easily render DOC or DOCX files into HTML webpages programmatically on the cloud. This enables viewing Word documents in any browser without exposing the original files. In this article, we will learn how to display a Word document in an HTML page using a REST API in PHP.
The following topics are covered:
- Word to HTML Viewer REST API and PHP SDK
- Display Word Document in HTML Page using REST API in PHP
- Embed Word Document into Existing HTML Page
- Display Word Document in HTML with Watermark using PHP
Word to HTML Viewer REST API and PHP SDK
To render Word documents as HTML, we use the PHP SDK of GroupDocs.Viewer Cloud API. It supports rendering and viewing of document and image file formats programmatically. Install the SDK with:
composer require groupdocscloud/groupdocs-viewer-cloud
After installation, load the Composer autoload to access the SDK:
require_once('vendor/autoload.php');
Obtain your Client ID and Secret from the dashboard before proceeding7. Insert them into the code as shown:
Display Word Document in HTML Page using REST API in PHP
Follow these steps to show a Word document as HTML:
- Upload the DOCX file to the cloud
- Display Word Document in HTML Page
- Download the rendered file
Upload the Document
Upload the DOCX file using the sample below:
The file appears in the files section of your cloud dashboard.
Display Word Document in HTML Page using PHP
Render the uploaded Word document to HTML with these steps:
- Create an instance of the ViewAPI.
- Create a ViewOptions object.
- Set the input file path.
- Choose HTML as the ViewFormat.
- Initialise an HtmlOptions object.
- Configure properties such as IsResponsive, ForPrinting, etc.
- Build a CreateViewRequest using the ViewOptions.
- Call the createView() method to render.
The code below demonstrates how to display a Word file in HTML using a REST API in PHP.

Display Word Document in HTML Page using REST API in PHP.
You can fine‑tune the rendering with these options:
- Render a specific page range
$renderOptions->setStartPageNumber(1);
$renderOptions->setCountPagesToRender(3);
- Render selected pages only
$renderOptions->setPagesToRender([1, 3]);
- View pages in a custom order
$renderOptions->setPagesToRender([2, 1]);
- Include comments in the output
$renderOptions->setRenderComments(true);
Download HTML Pages
The rendered HTML files are stored on the cloud and can be downloaded with the following code:
Embed Word Document into Existing HTML Page
Embed a Word document into an existing HTML page by following these steps:
- Create instances of the ViewAPI and FileAPI.
- Initialise a ViewOptions object.
- Set the input file path.
- Choose HTML as the ViewFormat.
- Initialise an HtmlOptions object.
- Configure properties such as IsResponsive, ForPrinting, etc.
- Build a CreateViewRequest with ViewOptions.
- Render with the createView method.
- Load an existing HTML file and retrieve the
<body>element. - Append each rendered page’s HTML to the body.
- Save the updated markup using
saveHTML(). - Write the final file with
file_put_contents().
The sample below shows how to embed a Word document into an existing HTML page using a REST API in PHP.

Embed a Word Document into an Existing HTML Page.
Display Word Document in HTML with Watermark using PHP
Add a watermark while rendering Word to HTML with these steps:
- Create an instance of the ViewAPI.
- Initialise a ViewOptions object.
- Set the input file path.
- Choose HTML as the ViewFormat.
- Create and assign a Watermark object.
- Define watermark size and text.
- Build a CreateViewRequest with ViewOptions.
- Render using the createView method.
The code sample demonstrates how to display a Word document in HTML with a watermark using a REST API in PHP.

Display Word Document in HTML with Watermark using PHP.
Try Online
Test the free online DOCX rendering tool built with this API: https://products.groupdocs.app/viewer/docx
Conclusion
In this article, we covered how to:
- View a Word document in a browser‑compatible HTML page using PHP
- Customize Word‑to‑HTML rendering options
- Embed a Word document into an existing HTML page
- Render Word content with a watermark
- Programmatically upload DOCX files to the cloud
- Download rendered HTML files from the cloud
Explore more about GroupDocs.Viewer Cloud API in the documentation. The API Reference lets you interact with the endpoints directly in your browser. For questions, visit the forum.