Listening to conversion process events
In some cases there is the need to monitor conversion process and to receive update for start, progress and completion of a conversion. For such situations GroupDocs.Conversion expose extension point where the client application may hook up and receive updates.
To enable listening you have to:
- Implement you own implementation of IConverterListener interface.
- Instantiate ConverterSettings class and pass an instance of the class created in first step
- Pass ConverterSettings object factory to constructor of a Converter class.
- Call Convertmethod of Converter class.
Here is a code that demonstrates how to enable listening for GroupDocs.Conversion.
public class ConverterListener implements IConverterListener
{
public void started()
{
System.out.println("Conversion started...");
}
public void progress(byte current)
{
System.out.println($"... " + current + "% ...");
}
public void completed()
{
System.out.println("... conversion completed");
}
}
IConverterListener listener = new ConverterListener();
ConverterSettings settingsFactory = new ConverterSettings
{
Listener = listener
};
try(Converter converter = new Converter("sample.docx", settingsFactory))
{
PdfConvertOptions options = new PdfConvertOptions();
converter.convert("converted.pdf", options);
}