Aspose::Words::WarningInfoCollection class
Contents
[
Hide
]WarningInfoCollection class
Represents a typed collection of WarningInfo objects. To learn more, visit the Programming with Documents documentation article.
class WarningInfoCollection : public IWarningCallback,
public System::Collections::Generic::IEnumerable<System::SharedPtr<Aspose::Words::WarningInfo>>
Methods
| Method | Description |
|---|---|
| Clear() | Removes all elements from the collection. |
| GetEnumerator() override | Returns an enumerator object that can be used to iterate over all items in the collection. |
| Warning(System::SharedPtr<Aspose::Words::WarningInfo>) override | Implements the IWarningCallback interface. Adds a warning to this collection. |
| WarningInfoCollection() | |
| get_Count() | Gets the number of elements contained in the collection. |
| idx_get(int32_t) | Gets an item at the specified index. |
| 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. |
Typedefs
| Typedef | Description |
|---|---|
| const_iterator | Const iterator type. |
| iterator | Iterator type. |
| iterator_holder_type | A collection type whose iterator types is used as iterator types in the current collection. |
| virtualized_iterator | Virtualized type. |
| virtualized_iterator_element | Virtualized element type. |
Remarks
You can use this collection object as the simplest form of IWarningCallback implementation to gather all warnings that Aspose.Words generates during a load or save operation. Create an instance of this class and assign it to the WarningCallback or WarningCallback property.
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>(System::String(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() == WarningType::FontSubstitution)
{
std::cout << info->get_Description() << std::endl;
}
}
See Also
- Interface IWarningCallback
- Namespace Aspose::Words
- Library Aspose.Words for C++