---
title: "Export Microsoft Word DOCX Ant task"
source: https://dev.pageseeder.com/guide/publishing/ant_api/extensions/task_export-docx.html
description: "The export-docx Ant task converts PSML documents to Microsoft Word DOCX format using configurable rules, templates, and parameters. It supports standalone use, custom document properties, token substitution, and post-processing capabilities."
last_updated: 2026-09-14T14:47:20+10:00
tokens: ~1622
---

# Task export-docx

This task can be used to convert a portable or processed PSML document to the Word`.docx` format according to rules defined in the [Export Microsoft Word DOCX config usage](/guide/publishing/ant_api/extensions/microsoft_word_docx_export_config_usage.md).

For a list of the latest changes, *see* [github](https://github.com/pageseeder/docx/releases).

To use this Ant extension standalone outside PageSeeder, you can download the `pso-docx-ant-x.jar` and `pso-docx-core-x.jar` files from [maven central](https://search.maven.org/search?q=g:org.pageseeder.docx).

## Task definition

Following are two examples of task definitions.

### Minimal

```xml

<export-docx src="[source]" />
```

### Full

```xml

<export-docx src="[source]"
             dest="[destination]"
             media="[media folder]"
             working="[working-directory]"
             wordTemplate="[template.docx]"
             config="[config.xml]">
  <param name="[param name]"
         value="[param value]"/> ...
</export-docx>
```

## Attributes

| **Attribute** | Description | Required |
| --- | --- | --- |
| **src** | Path to the source file to process. It must point to a ‘`.psml`’ XML file | Yes |
| **dest** | Path to the destination file (or folder if using `expanded`). Defaults to the name and location of the source with ‘.docx’ extension if unspecified. | No |
| **media ** | Path to media such as images referenced by the PSML. Images must not be in subfolders and must be referenced by their filename only. | No |
| **working** | The directory holding temporary files. Defaults to `[java.io.tmpdir]/antdocx-[number]` | No |
| **wordTemplate** | Path to .dotx template file | No |
| **config** | Path to .xml config file | No |

## Parameters

The following `@name` and `@value` attributes are valid for `<param>` elements – all are optional.

| Name | Value |
| --- | --- |
| `manual-core` | Whether to take Word document properties from template, xml config or manual params - allowed values `Template\|Config\|Manual` (default `Manual`) |
| `manual-creator` | Document Creator property |
| `manual-revision` | Document Revision property (must be an integer - *not visible in Word*) |
| `manual-created` | Document Created Date property |
| `manual-modified` | Document Modified Date property |
| `manual-version` | Document Version property (e.g. 1.0 - *not visible in Word unless there is a custom property in the template named Version*) |
| `manual-keywords` | Document Tags property |
| `manual-category` | Document Category property |
| `manual-title` | Document Title property |
| `manual-subject` | Document Subject property |
| `manual-description` | Document Comments property |
| `manual-master` | If `true` output docx as a master document with any `<blockxref>` to a word document as a subdocument |
| `current-user` | Full name of current user (required for `[ps-current-user]` token) |
| `expanded` | If `true` output docx in unzipped format. Requires pso-docx version `0.7.4` or higher |

As of pso-docx version `0.6.2`, the following tokens can be used for the `@value` of any of the `manual-` parameters above and are substituted with the corresponding value from PageSeeder.

| Token | Value |
| --- | --- |
| `[ps-current-user]` | The full name of the current user (requires `current-user` parameter) |
| `[ps-document-description]` | The PSML document description |
| `[ps-document-title]` | The PSML document title |
| `[ps-document-created]` | The PSML document created date |
| `[ps-document-modified]` | The PSML document modified date |
| `[ps-current-date]` | The current date |
| `[ps-document-labels]` | The PSML document labels |

## Usage

### Invoking in Ant

This task is included by default in the PageSeeder publisher, so `<taskdef/>` is only required when using it outside the publisher.

```xml
<project ... xmlns:psd="antlib:org.pageseeder.docx.ant">

  <!-- only required for standalone -->
  <taskdef uri="antlib:org.pageseeder.docx.ant" 
           resource="org/pageseeder/docx/ant/antlib.xml" 
           classpath="pso-docx-ant-0.5.9.jar"/>

  <target ... >
    <!-- Invoke Task -->
    <psd:export-docx src="test.psml" dest="result.docx">
      <param name="current-user"
             value="${ps.config.default.user.firstname}
                     ${ps.config.default.user.surname}" />
    </psd>
  </target>
</project>
```

Using a [namespace](https://ant.apache.org/manual/Types/namespace.html) is not required, but it is a good mechanism to know the origin of the task. The recommended namespace is ‘**psd**’.

### Standalone

It is designed to work as standalone. It is possible to invoke this task without being connected to PageSeeder.

Typically, this task would be used in the context of a PageSeeder export. In that case, use the [Task export](/guide/publishing/ant_api/tasks/task_export.md) and [Task process](/guide/publishing/ant_api/tasks/task_process.md) to download the source PSML file.

### How does it work?

This Ant task does the following:

1. Loads the config and template files.
2. Transforms the PSML into *docx* XML files.
3. Zips up the XML files and associated images into the *docx* format.

### Post processing

For custom formatting, it is sometimes useful to post-process the DOCX XML to add special formatting. The example ANT script code below does the following:

1. Uses the `expanded=true` parameter to output the unzipped DOCX files.
2. Runs an XSLT named `docx-post-transform.xsl`  to transform the `document.xml` file.
3. Zips the expanded files to create a `.docx` file.

```xml

...
<property name="working" value="${ps.config.default.working}" />
<property name="process" value="${working}/process" />
<property name="images" value="${working}/images" />
<property name="expanded" value="${working}/expanded" />
...

<psd:export-docx
    src="${process}/${ps.config.default.uri.filename.no.ext}.psml"
    dest="${expanded}"
    media="${images}"
    working="${working}/docx"
    config="word-export-config.xml"
    wordTemplate="word-export-template.docx">
  ...
  <param name="expanded" value="true"/>
</psd:export-docx>
<echo>DocX post-transform</echo>
<xslt
  in="${expanded}/word/document.xml"
  out="${working}/document.xml"
  style="docx-post-transform.xsl"/>
<copy
  todir="${expanded}/word"
  file="${working}/document.xml" overwrite="true"/>

<echo>Zipping</echo>
<zip
  destfile="${working}/${ps.config.default.uri.filename.no.ext}.docx"
  basedir="${expanded}"/>
...
```

