3. Converting an XML document to RTF

This second sample consists in three steps:

  1. Compile the XSLT style sheet for all subsequent uses.

  2. Invoke the XSLT engine to convert the input XML document to XSL-FO.

  3. Invoke XMLmind XSL-FO Converter to convert the temporary XSL-FO file generated by second step to RTF.

Excerpts of samples/dotnet/Sample2.cs:

using System.Xml.Xsl;
using XmlMind.FoConverter;

            XslCompiledTransform transform = new XslCompiledTransform();

            string xmlUri = ToUri(xmlPath);
            foPath = Path.GetTempFileName();
            transform.Transform(xmlUri, foPath);2

            Converter converter = new Converter();3
            converter.OutputFormat = OutputFormat.Rtf;
            converter.OutputEncoding = "windows-1252";
            converter.ImageResolution = 72;
            converter.BaseUrl = xmlUri;4



Compile the XSLT style sheet.

[Important]About the thread safety of XMLmind XSL-FO Converter

A Converter instance must not be shared between different threads.


Transform the XML input file to a temporary output file created in the system-dependant temporary file directory.


Create and parameterize a Converter object as explained in Section 2, “Converting an XSL-FO file to RTF”.


Setting the BaseUrl property to the URL of the XML input file is really needed in our case:

If the XML input file references graphics files using relative URLs (example: images/screenshot1.png), then the generated XSL-FO file is likely to contain fo:external-graphic objects referencing the same graphics files using the same relative URLs. The problem is that, in our case, the XSL-FO file is not generated in the same directory as the XML input file. Therefore, without the BaseUrl property, these relative URLs would be resolved incorrectly by XMLmind XSL-FO Converter.

An advanced alternative to specifying a BaseUrl property, is to specify an IUriResolver object using Converter.SetUriResolver.


Perform the conversion by invoking Converter.Convert.