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 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 bintray .

Definition

Minimal definition:

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

 Full definition:

<export-docx
    src="[source]"
    dest="[destination]"
    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 should point to a '.psml' XML file.Yes
destPath to the destination file (or folder if using expanded).
Will default to the name and location of the source with '.docx' extension if unspecified.
No
workingThe directory holding temporary files. Defaults to [java.io.tmpdir]/antdocx-[number].No
wordTemplatePath to .dotx template file.No
configPath to .xml config file.No

Parameters

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

NameValue
manual-coreWhether to take Word document properties from dotx 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)
manual-keywordsDocument Tags property
manual-categoryDocument Category property
manual-titleDocument Title property
manual-subjectDocument Subject property
manual-descriptionDocument Comments property
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 later.

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 will be substituted with the correspond 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 will:

  1. Load the config and template files.
  2. Transform the PSML into docx XML files.
  3. Zip 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="expanded" value="${working}/expanded" />
...

<psd:export-docx
    src="${process}/${ps.config.default.uri.filename.no.ext}.psml"
    dest="${expanded}"
    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