Listening to conversion process events

In some cases, there is a need to monitor the conversion process and to receive updates upon a start, progress and completion of a conversion. For such situations, GroupDocs.Conversion exposes an extension point where the client application may hook up and receive updates. 

To enable listening, follow these steps:

  1. Create your own implementation of the IConverterListener interface.
  2. Instantiate the ConverterSettings class and pass an instance of the class created in the first step.
  3. Pass the ConverterSettings object factory to the constructor of the Converter class.
  4. Call the Convert method of the Converter class.

The following code snippet shows how to enable listening for GroupDocs.Conversion events:

using GroupDocs.Conversion;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.Reporting;

IConverterListener listener = new ConverterListener();
Func<ConverterSettings> settingsFactory = () => new ConverterSettings
{
    Listener = listener
};
using (Converter converter = new Converter("sample.docx", settingsFactory))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

public class ConverterListener : IConverterListener
{
    public void Started()
    {
        Console.WriteLine("Conversion started...");
    }
    public void Progress(byte current)
    {
        Console.WriteLine($"... {current} % ...");
    }
    public void Completed()
    {
        Console.WriteLine("... conversion completed");
    }
}