Skip to main content

 Publishing

Publishing PageSeeder data to print, the Web or both

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.

For a list of the latest changes, see github .

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 .

Task definition

Following are two examples of task definitions. 

Minimal

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

Full

<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

AttributeDescriptionRequired
srcPath to the source file to process. It must point to a ‘.psml’ XML fileYes
destPath 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
workingThe directory holding temporary files. Defaults to [java.io.tmpdir]/antdocx-[number]No
wordTemplatePath to .dotx template fileNo
configPath to .xml config fileNo

Parameters

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

NameValue
manual-coreWhether to take Word document properties from template, xml config or manual params - allowed values Template|Config|Manual (default Manual)
manual-creatorDocument Creator property
manual-revisionDocument Revision property (must be an integer - not visible in Word)
manual-createdDocument Created Date property
manual-modifiedDocument Modified Date property
manual-versionDocument Version property (e.g. 1.0 - not visible in Word unless there is a custom property in the template named Version)
manual-keywordsDocument Tags property
manual-categoryDocument Category property
manual-titleDocument Title property
manual-subjectDocument Subject property
manual-descriptionDocument Comments property
manual-masterIf true output docx as a master document with any <blockxref> to a word document as a subdocument
current-userFull name of current user (required for [ps-current-user] token)
expandedIf 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.

TokenValue
[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.

<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  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 and Task process 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.
...
<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}"/>
...
Created on , last edited on