Listening to conversion process events
Leave feedback
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:
- Create your own implementation of the IConverterListener interface.
- Instantiate the ConverterSettings class and pass an instance of the class created in the first step.
- Pass the ConverterSettings object factory to the constructor of the Converter class.
- 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");
}
}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.