[First] [Previous] [Next] [Last] [Contents]

# 5 Using Writer2LaTeX from another Java application

Version 0.5 features a new API to use Writer2LaTeX from another Java application. Please see the javadoc for the package writer2latex.api for details.

Here's a simple example8 showing how to convert a file to LaTeX using a custom configuration (excluding exception handling):

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.util.Enumeration;

import writer2latex.api.*;

import writer2latex.util.Config;

// Create a LaTeX converter

ConverterFactory factory = new ConverterFactory();

Converter converter =

factory.createConverter("application/x-latex");

// Create a configuration

Config config = new Config();

config.read(new FileInputStream("myconfig.xml"));

config.setOption("inputencoding","latin1");

converter.setConfig(config);

// Convert the document

ConverterResult result =

converter.convert(new FileInputStream("mydocument.odt"),

"mydocument.tex");

// Write the files

Enumeration docEnum = dataOut.getDocumentEnumeration();

while (docEnum.hasMoreElements()) {

OutputFile docOut = (OutputFile) docEnum.nextElement();

FileOutputStream fos =

new FileOutputStream(docOut.getFileName());

docOut.write(fos);

fos.flush();

fos.close();

}

8 The handling of the configuration will change in version 1.0.