Track Document Conversion Progress

Track Document Conversion Progress

Aspose.Email provides the facility to track the document conversion progress. For this, the API provides SaveOptions.CustomProgressHandler. which represents the method that handles the progress events. The progress event types are represented by the ProgressEventType enumeration. The ProgressEventType enumeration has the following members.

The following sample code demonstrates the use of SaveOptions.CustomProgressHandler and ProgressEventType enumeration track the document conversion progress.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
public static void main(String[] args) {
    // The path to the resource directory.
    String dataDir = "data/";

    MailMessage msg = MailMessage.load(dataDir + "test.eml");

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    EmlSaveOptions opt = new EmlSaveOptions(MailMessageSaveType.getEmlFormat());
    opt.setCustomProgressHandler(new ConversionProgressEventHandler() {
        public void invoke(ProgressEventHandlerInfo info) {
            showEmlConversionProgress(info);
        }
    });

    msg.save(bos, opt);
}

private static void showEmlConversionProgress(ProgressEventHandlerInfo info) {
    switch (info.getEventType()) {
        case ProgressEventType.MimeStructureCreated:
            System.out.println("MimeStructureCreated - TotalMimePartCount: " + info.getTotalMimePartCount());
            System.out.println("MimeStructureCreated - SavedMimePartCount: " + info.getSavedMimePartCount());
            break;
        case ProgressEventType.MimePartSaved:
            System.out.println("MimePartSaved - TotalMimePartCount: " + info.getTotalMimePartCount());
            System.out.println("MimePartSaved - SavedMimePartCount: " + info.getSavedMimePartCount());
            break;
        case ProgressEventType.SavedToStream:
            System.out.println("SavedToStream - TotalMimePartCount: " + info.getTotalMimePartCount());
            System.out.println("SavedToStream - SavedMimePartCount: " + info.getSavedMimePartCount());
            break;
    }
}