We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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;
        <span style="color:blue;">try</span>
        {
            <span style="color:green;">//FullconvertedMultiTiffName = Path.Combine(OutputFolder, Path.GetFileNameWithoutExtension(FullInputFileName) + ".TIF");</span>
            <span style="color:blue;">if</span> (!<span style="color:#2b91af;">Directory</span>.Exists(OutputFolder))
            {
                <span style="color:#2b91af;">Directory</span>.CreateDirectory(OutputFolder);
            }
            Aspose.Words.<span style="color:#2b91af;">Document</span> doc = <span style="color:blue;">new</span> Aspose.Words.<span style="color:#2b91af;">Document</span>(FullInputFileName);
            <span style="color:#2b91af;">ImageSaveOptions</span> options = <span style="color:blue;">new</span> <span style="color:#2b91af;">ImageSaveOptions</span>(Aspose.Words.<span style="color:#2b91af;">SaveFormat</span>.Tiff);
            options.Resolution = 200;
            options.TiffCompression = <span style="color:#2b91af;">TiffCompression</span>.Ccitt4;
            options.ImageBrightness = .40f;
            <span style="color:#2b91af;">Stream</span> output = <span style="color:blue;">null</span>;
            sourceImages = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Image</span>[doc.PageCount];

            <span style="color:blue;">for</span> (<span style="color:blue;">int</span> page = 0; page < doc.PageCount; page++)
            {
                output = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();
              
                options.PageIndex = page;
                options.PageCount = 1;
                <span style="color:green;">//sourceImages[page - 1] = System.Drawing.Image.FromStream(output);</span>
               
             
                doc.Save(output,options);
                sourceImages[page] = System.Drawing.<span style="color:#2b91af;">Image</span>.FromStream(output);
                sourceImages[page].Save(<span style="color:#2b91af;">Path</span>.Combine(OutputFolder, <span style="color:#2b91af;">String</span>.Concat(<span style="color:#2b91af;">Path</span>.GetFileNameWithoutExtension(FullInputFileName), page.ToString().PadLeft(3, <span style="color:#a31515;">'0'</span>), <span style="color:#a31515;">"."</span>, <span style="color:#a31515;">"tiff"</span>)));
                

                
            }
            <span style="color:blue;">return</span> sourceImages;  
           
        }
        <span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)
        {
            <span style="color:blue;">throw</span> <span style="color:blue;">new</span> <span style="color:#2b91af;">Exception</span>(<span style="color:#2b91af;">String</span>.Format(<span style="color:#a31515;">"Error converting {0} to Tiff : {1}"</span>, <span style="color:#2b91af;">Path</span>.GetFileNameWithoutExtension(FullInputFileName), ex.Message));
        }
      

    }<br><br>Regards<br>Anish<br></pre><br>

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);<o:p></o:p>

options.Resolution = 200;

options.TiffCompression = TiffCompression.Ccitt4;

options.ImageBrightness = .40f;

options.WarningCallback = new HandleDocumentWarnings();


public class HandleDocumentWarnings : IWarningCallback<o:p></o:p>

{

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
{
    <span style="color:blue;">public</span> <span style="color:blue;">void</span> Warning(WarningInfo info)
    {

        <span style="color:#2b91af;">Console</span>.WriteLine(info.WarningType + <span style="color:#a31515;">": "</span> + info.Description);

    }

}</pre>I am using Aspose.Words v9.7.0.0<br><br>Can you please help me ?<br><br>Regards<br>Anish<br><pre style="font-family:Consolas;font-size:13;color:black;background:white;">


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)