Aspose::Words::IWarningCallback interface
Contents
[
Hide
]IWarningCallback interface
Implement this interface if you want to have your own custom method called to capture loss of fidelity warnings that can occur during document loading or saving.
class IWarningCallback : public virtual System::Object
Methods
Method | Description |
---|---|
GetType() const override | |
Is(const System::TypeInfo&) const override | |
static Type() | |
virtual Warning(System::SharedPtr<Aspose::Words::WarningInfo>) | 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. |
Examples
Shows how to set the property for finding the closest match for a missing font from the available font sources.
// Open a document that contains text formatted with a font that does not exist in any of our font sources.
auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Missing font.docx");
// Assign a callback for handling font substitution warnings.
auto warningCollector = System::MakeObject<Aspose::Words::WarningInfoCollection>();
doc->set_WarningCallback(warningCollector);
// Set a default font name and enable font substitution.
auto fontSettings = System::MakeObject<Aspose::Words::Fonts::FontSettings>();
fontSettings->get_SubstitutionSettings()->get_DefaultFontSubstitution()->set_DefaultFontName(u"Arial");
fontSettings->get_SubstitutionSettings()->get_FontInfoSubstitution()->set_Enabled(true);
// Original font metrics should be used after font substitution.
doc->get_LayoutOptions()->set_KeepOriginalFontMetrics(true);
// We will get a font substitution warning if we save a document with a missing font.
doc->set_FontSettings(fontSettings);
doc->Save(get_ArtifactsDir() + u"FontSettings.EnableFontSubstitution.pdf");
for (auto&& info : warningCollector)
{
if (info->get_WarningType() == Aspose::Words::WarningType::FontSubstitution)
{
std::cout << info->get_Description() << std::endl;
}
}
See Also
- Namespace Aspose::Words
- Library Aspose.Words for C++