2. Converting an XSL-FO file to RTF

This first sample consists in a single step: invoke XMLmind XSL-FO Converter to convert the input XSL-FO file to RTF.

Note that converting XSL-FO to other formats is simply a matter of changing the value of the OutputFormat property. The possible values for this property are: OutputFormat.Rtf, OutputFormat.Wml, OutputFormat.Docx, OutputFormat.Odt.

Excerpts of samples/dotnet/Sample1.cs:

using XmlMind.FoConverter;

...
            Converter converter = new Converter();1
            converter.OutputFormat = OutputFormat.Rtf;2
            converter.OutputEncoding = "windows-1252";
            converter.ImageResolution = 120;

            String inUri = ToUri(inPath);
            converter.SetInput(inUri);3
            converter.SetOutput(outPath);4
            converter.Convert();5
...

1

Create a new Converter object.

2

Parameterize the Converter using some of its properties.

Note that specifying property OutputEncoding is really useful only in the case of the RTF format. All the other formats are XML-based and thus, the default value of OutputEncoding, generally UTF-8, should work fine in all cases.

3

Specify the input source of the Converter using Converter.SetInput.

Here we use the most high-level specification: we specify a (%-escaped) URI. In production, you'll generally specify a Stream, TextReader or XMLReader. Note that when you'll specify a Stream, TextReader or XMLReader, the Converter will not automatically close it at the end of the conversion. You'll have to do that yourself. The rule here is: the code which has opened a Stream, TextReader or XMLReader has the responsibility to close it.

[Note]

ToURI is a simple helper function implemented as follows:

private static string ToUri(String fileName)
{
    Uri uri = new Uri(Path.GetFullPath(fileName));
    return uri.AbsoluteUri;
}

4

Specify the output destination of the Converter using Converter.SetOutput.

Here we use the most high-level specification: we specify a file path. In production, you'll generally specify a Stream or a TextWriter. As explained before, when you'll specify a Stream or a TextWriter, the Converter will not automatically close it at the end of the conversion.

5

Perform the conversion by invoking Converter.Convert.