Home

Contents

1 Introduction

2 Using the export filters

3 Using the command line utility

4 Configuration

5 Special features for the EPUB export

6 The LaTeX package ooomath.sty

7 Using Writer2LaTeX from another application

7.1 Using Writer2LaTeX from a Java application

7.2 Using Writer2LaTeX from a Basic macro

7.3 Batch conversion with UNO

7.4 Converting from StarMath with a Basic macro

8 Troubleshooting

    

7 Using Writer2LaTeX from another application

7.1 Using Writer2LaTeX from a Java application

Writer2LaTeX features a simple API to convert documents from another Java application. Please see the javadoc for writer2latex.jar (the package writer2latex.api) for details.

The API offers a stream based as well as a file based interface for conversions.

Here's a simple example showing how to convert a file to LaTeX using a custom configuration (excluding exception handling) using the file based methods of the API.

import java.io.File;

import writer2latex.api.*;

 

// Create a LaTeX converter

Converter converter =

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

 

// Configure the converter

Config config = converter.getConfig();

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

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

 

// Convert the document

ConverterResult result =

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

        "mydocument.tex");

 

// Write the files

result.write(new File("mydirectory"));

Using the stream based methods the conversion may look like this (assuming the option save_images_in_subdir is set to false):

import java.io.FileInputStream;

import java.io.FileOutputStream;

 

// Convert the document

ConverterResult result =

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

    "mydocument.tex");

 

// Write the files

Iterator<OutputFile> docs = result.iterator();

while (docs.hasNext()) {

    OutputFile docOut = (OutputFile) docs.next();

    FileOutputStream fos =

        new FileOutputStream("mydirectory/"+docOut.getFileName());

    docOut.write(fos);

    fos.flush();

    fos.close();

}

Writer2LaTeX also offers an interface for batch conversion of a directory into XHTML. For at simple example, see the source of Application.java.