iWarningCall back in Aspose.word

Hi Team,

I am converting a word document to single page tiff images by using he below code.

Here how can i implement the iWarningCallback interface and what is the benefit by implement this .

Please see the current code which i am using to convert document to single page tiff

public static System.Drawing.Image[] ConvertWordToSingleTiff(string OutputFolder, string FullInputFileName)
{
    System.Drawing.Image[] sourceImages = null;
 
    try
    {
        //FullconvertedMultiTiffName = Path.Combine(OutputFolder, Path.GetFileNameWithoutExtension(FullInputFileName) + ".TIF");
        if (!Directory.Exists(OutputFolder))
        {
            Directory.CreateDirectory(OutputFolder);
        }
        Aspose.Words.Document doc = new Aspose.Words.Document(FullInputFileName);
        ImageSaveOptions options = new ImageSaveOptions(Aspose.Words.SaveFormat.Tiff);
        options.Resolution = 200;
        options.TiffCompression = TiffCompression.Ccitt4;
        options.ImageBrightness = .40f;
        Stream output = null;
        sourceImages = new System.Drawing.Image[doc.PageCount];
 
        for (int page = 0; page < doc.PageCount; page++)
        {
            output = new MemoryStream();
                  
            options.PageIndex = page;
            options.PageCount = 1;
            //sourceImages[page - 1] = System.Drawing.Image.FromStream(output);
                 
            doc.Save(output,options);
            sourceImages[page] = System.Drawing.Image.FromStream(output);
            sourceImages[page].Save(Path.Combine(OutputFolder, String.Concat(Path.GetFileNameWithoutExtension(FullInputFileName), page.ToString().PadLeft(3, '0'), ".", "tiff")));
        }
        return sourceImages;  
               
    }
    catch (Exception ex)
    {
        throw new Exception(String.Format("Error converting {0} to Tiff : {1}", Path.GetFileNameWithoutExtension(FullInputFileName), ex.Message));
    }
}

Regards
Anish

Hi Anish,

Thanks for your inquiry. You can simply specify an instance of class that implements IWarningCallback Interface to the ImageSaveOptions.WarningCallback property as follows:


ImageSaveOptions options = new ImageSaveOptions(Aspose.Words.SaveFormat.Tiff);
options.Resolution = 200;
options.TiffCompression = TiffCompression.Ccitt4;
options.ImageBrightness = .40 f;
options.WarningCallback = new HandleDocumentWarnings();


public class HandleDocumentWarnings : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        Console.WriteLine(info.WarningType + ": " + info.Description);
    }
}

Aspose.Words invokes this method when it encounters some issue during document loading or saving that might result in loss of formatting or data fidelity.

Best regards,

Hi Awais Hafeez

But when i try to include this in my code i am not getting the IWarningCallback interface.
Please see the error when i am trying to add the code

public class HandleDocumentWarnings : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        Console.WriteLine(info.WarningType + ": " + info.Description);
    }
}

I am using Aspose.Words v9.7.0.0

Can you please help me ?

Regards
Anish

Hi Anish,

Thanks for the additional information. The Warning mechanism doesn’t seem to work with ImageSaveOptions class; your thread has been linked to the appropriate issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best regards,

Hi Awais Hafeez,

Is there any update on this issue . Can you please let me know?

Regards
Anish

Hi Anish,

Thanks for your inquiry. Unfortunately, your issue is not resolved yet. The responsible developer has completed the analysis of this issue and the root cause has been determined. We will be sure to inform you as soon as this issue is resolved. We apologize for any inconvenience.

Best regards,

The issues you have found earlier (filed as WORDSNET-8363) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)