Webservice Addressing with the Ant Task Library

Minimum Requirements

  • Java version: 7
  • webPDF version: 7
  • ant-task version: 1

Ant task library

If you use Apache Ant, the question quickly comes up whether webPDF webservices can be called directly from an Ant target. That would make it possible to automate fixed webservice sequences and repeat them reliably for many documents.

Yes, It Can

The webPDF ant-task library provides simple tasks that let you start individual webPDF webservice calls or execute several of them in sequence.

The actual calls are executed via the webPDF wsclient library.

ant-task on GitHub and in Maven Central

The ant-task library is publicly available and free to use:

Maven dependency:

<dependency>
<groupId>net.webpdf</groupId>
<artifactId>webpdf-ant</artifactId>
<version>1.0.0</version>
</dependency>

Integration via Apache Ivy:

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
<info organisation="example" module="webpdf-ant-demo" />
<dependencies>
<dependency org="net.webpdf" name="webpdf-ant" rev="1.0.0" />
</dependencies>
</ivy-module>

Example: Calling a webPDF Webservice from an Ant Target

In the following example, files are read from a source folder, converted to PDF with the Converter webservice, and written to a target folder.

<?xml version="1.0" encoding="UTF-8"?>
<project name="webpdf-ant-example" default="executeWebPDFTask"
xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:webpdf="antlib:net.webpdf.ant">

<target name="executeWebPDFTask">
<mkdir dir="input" />
<mkdir dir="output" />

<ivy:resolve />
<ivy:cachepath pathid="webpdf.classpath" conf="default" />

<taskdef uri="antlib:net.webpdf.ant"
resource="net/webpdf/ant/antlib.xml"
classpathref="webpdf.classpath" />

<webpdf:webpdf serverurl="http://localhost:8080/webPDF"
targetdir="output"
failonerror="true">

<fileset dir="input">
<include name="**/*.png" />
</fileset>

<globmapper from="*.png" to="*.pdf" />

<webpdf:group>
<webpdf:operation>
<webpdf:converter />
</webpdf:operation>
</webpdf:group>

</webpdf:webpdf>
</target>
</project>

The webpdf Task

The webpdf task is the entry point and provides the basic options:

  • serverurl: address of the webPDF server
  • tempdir (optional): directory for temporary files
  • targetdir: output path for results
  • failonerror (optional): stop on the first error

If required, credentials can be provided via usercredentials:

<webpdf:usercredentials username="user" password="secret" />

Selecting Source Files

For input, you can use elements such as file or fileset:

<fileset dir="input">
<include name="**/*.png" />
</fileset>

operation and group Tasks

The desired webservice endpoint is defined inside the operation task, including its parameters as described in the documentation.

An operation task must always be placed inside a group task. A group can execute multiple operations in a fixed order.

Chaining Operations and Groups

Multiple operations in one group:

<webpdf:group>
<webpdf:operation>...</webpdf:operation>
<webpdf:operation>...</webpdf:operation>
</webpdf:group>

Multiple groups in sequence:

<webpdf:webpdf>
<webpdf:group>...</webpdf:group>
<webpdf:group>...</webpdf:group>
</webpdf:webpdf>

Using Input and Output Variables

For more complex workflows, intermediate results can be stored in variables and reused later:

  • OUTPUT: stores the result of a group
  • INPUT: explicitly sets a different source document for the next group

This makes it possible to build more robust branching and merging workflows, for example with merge.