Using the Muhimbi PDF Converter Services from Java Using Apache Axis2

Related Products

PDF Converter

PDF Converter


Many of our customers use the Muhimbi PDF Converter Services from Java based environments to Convert, Watermark, Merge and Secure common document types including MS-Office, AutoCAD, HTML and Images. This is made particularly easy because we ship Java based sample code with the product (in addition to C# samples).

However, to keep things as simple as possible, and the number of external dependencies to a minimum, so far our sample code has been using wsimport to generate Java based web service proxy classes. Unfortunately wsimport does not generate very friendly syntax and, even worse, does not support Web Services that expose derived classes (A feature used by some of our more advanced facilities).

All is not lost as Apache’s Axis2 Web Services framework solves both problems. The generated proxy classes are much easier to use and derived classes can be populated and sent to the server without problems.

Below you will find an example about how to setup Apache Axis, generate proxy classes and use those classes to convert a document to PDF. This is just a simple sample, for full details see the Developer Guide. It is assumed that you are familiar with Java. Our samples are generated using Microsoft Windows, please note that the command line syntax on other platforms may be slightly different.

The full version of the sample code discussed in this post, including pre generated proxies, is installed alongside each copy of the Muhimbi Converter Server Platform, starting with version 7.0. It is also available here and includes Windows batch files for generating the proxies, compiling and executing the code.

The example described below assumes the following:

  1. JDK 1.5 (or newer) has been installed and configured.
  2. JAVA\_HOME is set and javac is on the path.
  3. The Muhimbi Conversion Service and all prerequisites have been installed in line with the Administration Guide.
  4. The Muhimbi Conversion Service is running in the default anonymous mode. This is not an absolute requirement, but it makes initial experimentation much easier.

Installing Axis2

The installation process for Axis 2 is relatively simple. The steps are as follows:

  1. Download the Axis2 binary distribution
  2. Unpack and place axis2-<version> in a location of your choice. (This will be your AXIS2\_HOME).
  3. Have a look at installation-std-bin.txt and set environment variables depending on your platform.
  4. Add %AXIS2\_HOME%\\bin to your Path to make sure the executables can be found.
  5. On non-Windows Machines execute chmod 744 $AXIS2\_HOME/bin/\*.sh

Generating Proxies

With all the prerequisites in place you can generate proxy classes for the web service by executing the following command:

Feel free to change the package name to something more suitable to your organisation. The example below assumes is used.

If the Muhimbi Conversion Service is not located on the same system as where wsdl2java is executed then change localhost to the name of the server running the Conversion Service. You will also need to change the host name in the Conversion Service’s config file. A convenient shortcut to the Installation folder is located in the Muhimbi Start Menu Group. Open Muhimbi.DocumentConverter.Service.exe.config, search for baseAddress and change the host name. Restart the Muhimbi Document Converter Service to activate the change.

Sample Code

The sample code is as follows. Please note that exception handling has been omitted for the sake of clarity. This is a minimal example, for full details see the Developer Guide. (Download Source Code)

Compiling Code

How to compile your code very much depends on your environment, solution and build system. To build the sample code in this blog post use the following:

Please note that on non-Windows platforms the classpath (-cp) separator is : rather than ;.

Running the Code

To execute the code and carry out the PDF conversion of a file named test.docx issue the following command.

Please note that on non-Windows platforms the classpath (-cp) separator is : rather than ;.

If you have any questions then leave a comment below or contact us at

Labels: Articles, Java, pdf, PDF Converter Services

Have a Question?
We’re Always Happy to Help.

© Muhimbi Ltd. 2008 - 2024
This website uses cookies to ensure you get the best experience. Learn more