Publishing Engine Programmer's Guide > The Arbortext Publishing Engine Sub-Process > Writing Arbortext PE Applications in Java > Calling the Conversion Processor From a Java Arbortext PE Application
  
Calling the Conversion Processor From a Java Arbortext PE Application
You can write a Java application that can call the conversion processor (explained in Arbortext Publishing Engine Document Conversion) by importing the following packages from PE_HOME\lib\classes\peclient.jar:
com.arbortext.e3.DocumentConverter
com.arbortext.e3.DocumentConverterException
Call the conversion processor by calling the static method:
com.arbortext.e3.DocumentConverter.doConvert(
String inFile,
String outFile,
Map params
);
The parameter inFile must specify the absolute path to a document to be converted. The com.arbortext.e3.DocumentConverter.doConvert method does not process open documents. If your application creates or modifies a document that will be converted, you must save the document to disk and close it before invoking doConvert. After doConvert returns, you can open your document again if you need to make further modifications.
The parameter outFile must specify the absolute path to the output file that doConvert will produce. If this file already exists, it will be overwritten during conversion processing.
The parameter params must be a Java map with String keys and values. Each parameter entry must correspond to a supported conversion parameter (refer to Document Conversion Parameters for a list and descriptions).
For example, to specify a stylesheet:
params.put( "stylesheet", "c:\absolute\path\to\stylesheet.style" );
The doConvert method has no return value. If an error occurs during processing, it throws a com.arbortext.e3.subprocess.DocumentConverterException, which has two methods:
getReason returns the HTML reason code (400, 500, or some other valid code)
getPage returns the XHTML page describing the error (the same page an f=convert request would return to an HTTP client)
The following is an example of Java code that calls com.arbortext.e3.DocumentConverter.doConvert:
import com.arbortext.e3.subprocess.DocumentConverter;
import com.arbortext.e3.subprocess.DocumentConverterException;

String inFile = "c:\absolute\path\to\input\file.xml";
String outFile = "c:\absolute\path\to\output\file.pdf";
Map params = new HashMap();
params.put( "type","pdf" );
params.put( "stylesheet" , "d:\absolute\path\to\stylesheet.style" );
try {
DocumentConverter.doConvert( inFile, outFile, params );
// Conversion succeeded
}
catch( DocumentConverterException e ) {
String reason = e.getReason();
String page = e.getPage();
// Log the failure and exit.
}