PHPackages                             ephpoffice/phpword - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. ephpoffice/phpword

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

ephpoffice/phpword
==================

PHPWord - Read, Create and Write Word documents in PHP

0.7.0(12y ago)0346LGPLPHPPHP &gt;=5.3.0

Since Jan 28Pushed 12y ago1 watchersCompare

[ Source](https://github.com/ephp/PHPWord)[ Packagist](https://packagist.org/packages/ephpoffice/phpword)[ Docs](http://phpoffice.github.io)[ RSS](/packages/ephpoffice-phpword/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (3)Used By (0)

PHPWord
=======

[](#phpword)

[![Build Status](https://camo.githubusercontent.com/4a0e916571ed921f87a11d1749d6f99a2f3f013784fc53909af0e8ae5cf0fdcd/68747470733a2f2f7472617669732d63692e6f72672f5048504f66666963652f504850576f72642e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/PHPOffice/PHPWord)[![Latest Stable Version](https://camo.githubusercontent.com/7b9f38de1b2dd5cd3a86914bdb25d475786c9f6c1cb6d8e19d8a8f2dde1efe99/68747470733a2f2f706f7365722e707567782e6f72672f7068706f66666963652f706870776f72642f762f737461626c652e706e67)](https://packagist.org/packages/phpoffice/phpword) [![Total Downloads](https://camo.githubusercontent.com/d97df9d916eb9121ab930ceb61b76d4c525a183a90b29b2ae7dd3769f96289ab/68747470733a2f2f706f7365722e707567782e6f72672f7068706f66666963652f706870776f72642f646f776e6c6f6164732e706e67)](https://packagist.org/packages/phpoffice/phpword) [![Latest Unstable Version](https://camo.githubusercontent.com/4e9fb73059203ad93c2fc61da5bab856b1b3c8d6651dbf1b8555c097bde13051/68747470733a2f2f706f7365722e707567782e6f72672f7068706f66666963652f706870776f72642f762f756e737461626c652e706e67)](https://packagist.org/packages/phpoffice/phpword) [![License](https://camo.githubusercontent.com/080d360620a1abbf69ace6acaf1f9c97c8ede891bee8820c1fca463358a835b6/68747470733a2f2f706f7365722e707567782e6f72672f7068706f66666963652f706870776f72642f6c6963656e73652e706e67)](https://packagist.org/packages/phpoffice/phpword)

**OpenXML - Read, Write and Create Word documents in PHP.**

PHPWord is a library written in PHP that create word documents.

No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be opened by all major office software.

**Want to contribute?** Fork us!

Requirements
------------

[](#requirements)

- PHP version 5.3.0 or higher

Installation
------------

[](#installation)

It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add the following lines to your `composer.json`.

```
{
    "require": {
       "phpoffice/phpword": "dev-master"
    }
}
```

Documentation
-------------

[](#documentation)

### Table of contents

[](#table-of-contents)

1. [Basic usage](#basic-usage)
    - [Measurement units](#measurement-units)
2. [Sections](#sections)
    - [Section settings](#section-settings)
    - [Section page numbering](#section-page-numbering)
3. [Texts](#texts)
    - [Attributes](#text-attributes)
4. [Paragraph Style](#paragraph-style)
    - [Attributes](#paragraph-style-attributes)
5. [Tables](#tables)
    - [Cell Style](#tables-cell-style)
6. [Images](#images)
    - [Attributes](#images-attributes)

#### Basic usage

[](#basic-usage)

The following is a basic example of the PHPWord library.

```
$PHPWord = new PHPWord();

// Every element you want to append to the word document is placed in a section.
// To create a basic section:
$section = $PHPWord->createSection();

// After creating a section, you can append elements:
$section->addText('Hello world!');

// You can directly style your text by giving the addText function an array:
$section->addText('Hello world! I am formatted.',
    array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));

// If you often need the same style again you can create a user defined style
// to the word document and give the addText function the name of the style:
$PHPWord->addFontStyle('myOwnStyle',
    array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
$section->addText('Hello world! I am formatted by a user defined style',
    'myOwnStyle');

// You can also put the appended element to local object like this:
$fontStyle = new PHPWord_Style_Font();
$fontStyle->setBold(true);
$fontStyle->setName('Verdana');
$fontStyle->setSize(22);
$myTextElement = $section->addText('Hello World!');
$myTextElement->setFontStyle($fontStyle);

// Finally, write the document:
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('helloWorld.docx');
```

##### Measurement units

[](#measurement-units)

The base length unit in Open Office XML is twip. Twip means "TWentieth of an Inch Point", i.e. 1 twip = 1/1440 inch.

You can use PHPWord helper functions to convert inches, centimeters, or points to twips.

```
// Paragraph with 6 points space after
$PHPWord->addParagraphStyle('My Style', array(
    'spaceAfter' => PHPWord_Shared_Font::pointSizeToTwips(6))
);

$section = $PHPWord->createSection();
$sectionStyle = $section->getSettings();
// half inch left margin
$sectionStyle->setMarginLeft(PHPWord_Shared_Font::inchSizeToTwips(.5));
// 2 cm right margin
$sectionStyle->setMarginRight(PHPWord_Shared_Font::centimeterSizeToTwips(2));
```

#### Sections

[](#sections)

Every visible element in word is placed inside of a section. To create a section, use the following code:

```
$section = $PHPWord->createSection($sectionSettings);
```

The `$sectionSettings` is an optional associative array that sets the section. Example:

```
$sectionSettings = array(
    'orientation' => 'landscape',
    'marginTop' => 600,
    'colsNum' => 2,
);
```

##### Section settings

[](#section-settings)

Below are the available settings for section:

- `orientation` Page orientation, i.e. 'portrait' (default) or 'landscape'
- `marginTop` Page margin top in twips
- `marginLeft` Page margin left in twips
- `marginRight` Page margin right in twips
- `marginBottom` Page margin bottom in twips
- `borderTopSize` Border top size in twips
- `borderTopColor` Border top color
- `borderLeftSize` Border left size in twips
- `borderLeftColor` Border left color
- `borderRightSize` Border right size in twips
- `borderRightColor` Border right color
- `borderBottomSize` Border bottom size in twips
- `borderBottomColor` Border bottom color
- `headerHeight` Spacing to top of header
- `footerHeight` Spacing to bottom of footer
- `colsNum` Number of columns
- `colsSpace` Spacing between columns
- `breakType` Section break type (nextPage, nextColumn, continuous, evenPage, oddPage)

The following two settings are automatically set by the use of the `orientation` setting. You can alter them but that's not recommended.

- `pageSizeW` Page width in twips
- `pageSizeH` Page height in twips

##### Section page numbering

[](#section-page-numbering)

You can change a section page numbering.

```
$section = $PHPWord->createSection();
$section->getSettings()->setPageNumberingStart(1);
```

#### Texts

[](#texts)

Text can be added by using `addText` and `createTextRun` method. `addText` is used for creating simple paragraphs that only contain texts with the same style. `createTextRun` is used for creating complex paragraphs that contain text with different style (some bold, other italics, etc) or other elements, e.g. images or links.

`addText` sample:

```
$fontStyle = array('name' => 'Times New Roman', 'size' => 9);
$paragraphStyle = array('align' => 'both');
$section->addText('I am simple paragraph', $fontStyle, $paragraphStyle);
```

`createTextRun` sample:

```
$textrun = $section->createTextRun();
$textrun->addText('I am bold', array('bold' => true));
$textrun->addText('I am italic, array('italic' => true));
$textrun->addText('I am colored, array('color' => 'AACC00'));
```

##### Attributes

[](#attributes)

- `size` text size, e.g. *20*, *22*,
- `name` font name, e.g. *Arial*
- `bold` text is bold, *true* or *false*
- `italic` text is italic, *true* or *false*
- `superScript` text is super script, *true* or *false*
- `subScript` text is sub script, *true* or *false*
- `underline` text is underline, *true* or *false*
- `strikethrough` text is strikethrough, *true* or *false*
- `color` text color, e.g. *FF0000*
- `fgColor` fgColor
- `line-height` text line height, e.g. *1.0*, *1.5*, ect...

#### Paragraph Style

[](#paragraph-style)

##### Attributes

[](#attributes-1)

- `line-height` text line height, e.g. *1.0*, *1.5*, ect...
- `align` paragraph alignment, *left*, *right* or *center*
- `spaceBefore` space before Paragraph
- `spaceAfter` space after Paragraph
- `tabs` set of Custom Tab Stops
- `indent` indent by how much

#### Tables

[](#tables)

The following illustrates how to create a table.

```
$table = $section->addTable();
$table->addRow();
$table->addCell();
```

##### Cell Style

[](#cell-style)

###### Cell Span

[](#cell-span)

You can span a cell on multiple columms.

```
$cell = $table->addCell(200);
$cell->getStyle()->setGridSpan(5);
```

#### Images

[](#images)

You can add images easily using the following example.

```
$section = $PHPWord->createSection();
$section->addImage('mars.jpg');
```

##### Attributes

[](#attributes-2)

- `width` width in pixels
- `height` height in pixels
- `align` image alignment, *left*, *right* or *center*
- `marginTop` top margin in inches, can be negative
- `marginLeft` left margin in inches, can be negative
- `wrappingStyle` can be *inline*, *square*, *tight*, *behind*, *infront*

To add an image with attributes, consider the following example.

```
$section->addImage(
    'mars.jpg',
    array(
        'width' => 100,
        'height' => 100,
        'marginTop' => -1,
        'marginLeft' => -1,
        'wrappingStyle' => 'behind'
    )
);
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 51% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4493d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a5afbeefc4f2d3f4d94e66cabfbf064f16df3e4abd963b883ae3bfd746af76f?d=identicon)[ephp](/maintainers/ephp)

---

Top Contributors

[![Progi1984](https://avatars.githubusercontent.com/u/1533248?v=4)](https://github.com/Progi1984 "Progi1984 (79 commits)")[![ivanlanin](https://avatars.githubusercontent.com/u/15313?v=4)](https://github.com/ivanlanin "ivanlanin (47 commits)")[![gabrielbull](https://avatars.githubusercontent.com/u/671923?v=4)](https://github.com/gabrielbull "gabrielbull (17 commits)")[![jeroenmoors](https://avatars.githubusercontent.com/u/1665245?v=4)](https://github.com/jeroenmoors "jeroenmoors (6 commits)")[![RLovelett](https://avatars.githubusercontent.com/u/335572?v=4)](https://github.com/RLovelett "RLovelett (1 commits)")[![deds](https://avatars.githubusercontent.com/u/1493642?v=4)](https://github.com/deds "deds (1 commits)")[![SergeC](https://avatars.githubusercontent.com/u/1062847?v=4)](https://github.com/SergeC "SergeC (1 commits)")[![hskrtich](https://avatars.githubusercontent.com/u/1214484?v=4)](https://github.com/hskrtich "hskrtich (1 commits)")[![jlocashio](https://avatars.githubusercontent.com/u/1380795?v=4)](https://github.com/jlocashio "jlocashio (1 commits)")[![maartenba](https://avatars.githubusercontent.com/u/485230?v=4)](https://github.com/maartenba "maartenba (1 commits)")

---

Tags

phpdocworddocxwriterrtf

### Embed Badge

![Health badge](/badges/ephpoffice-phpword/health.svg)

```
[![Health](https://phpackages.com/badges/ephpoffice-phpword/health.svg)](https://phpackages.com/packages/ephpoffice-phpword)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
