IWarningCallback Interface |
Namespace: Aspose.Words
The IWarningCallback type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | Warning |
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.
|
public class HandleDocumentWarnings : IWarningCallback { /// <summary> /// Our callback only needs to implement the "Warning" method. This method is called whenever there is a /// potential issue during document processing. The callback can be set to listen for warnings generated during document /// load and/or document save. /// </summary> public void Warning(WarningInfo info) { // We are only interested in fonts being substituted if (info.WarningType == WarningType.FontSubstitution) { Console.WriteLine("Font substitution: " + info.Description); } } }
// Load the document to render Document doc = new Document(MyDir + "Document.docx"); // Create a new class implementing IWarningCallback and assign it to the PdfSaveOptions class HandleDocumentWarnings callback = new HandleDocumentWarnings(); doc.WarningCallback = callback; // We can choose the default font to use in the case of any missing fonts FontSettings.DefaultInstance.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName = "Arial"; // For testing we will set Aspose.Words to look for fonts only in a folder which doesn't exist. Since Aspose.Words won't // find any fonts in the specified directory, then during rendering the fonts in the document will be substituted with the default // font specified under FontSettings.DefaultFontName. We can pick up on this substitution using our callback FontSettings.DefaultInstance.SetFontsFolder(string.Empty, false); // Pass the save options along with the save path to the save method doc.Save(ArtifactsDir + "Font.SubstitutionNotification.pdf");
Document doc = new Document(MyDir + "WMF with image.docx"); MetafileRenderingOptions metafileRenderingOptions = new MetafileRenderingOptions { EmulateRasterOperations = false, RenderingMode = MetafileRenderingMode.VectorWithFallback }; // If Aspose.Words cannot correctly render some of the metafile records to vector graphics then Aspose.Words renders this metafile to a bitmap HandleDocumentWarnings callback = new HandleDocumentWarnings(); doc.WarningCallback = callback; PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.MetafileRenderingOptions = metafileRenderingOptions; doc.Save(ArtifactsDir + "PdfSaveOptions.HandleBinaryRasterWarnings.pdf", saveOptions); Assert.AreEqual(1, callback.Warnings.Count); Assert.True(callback.Warnings[0].Description.Contains("R2_XORPEN")); } public class HandleDocumentWarnings : IWarningCallback { /// <summary> /// Our callback only needs to implement the "Warning" method. This method is called whenever there is a /// potential issue during document processing. The callback can be set to listen for warnings generated during document /// load and/or document save. /// </summary> public void Warning(WarningInfo info) { // For now type of warnings about unsupported metafile records changed from // DataLoss/UnexpectedContent to MinorFormattingLoss if (info.WarningType == WarningType.MinorFormattingLoss) { Console.WriteLine("Unsupported operation: " + info.Description); Warnings.Warning(info); } } public WarningInfoCollection Warnings = new WarningInfoCollection(); }