[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Expand]RichEditControl Document
   [Expand]Fields
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    Spell Checking
    AutoCorrect
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
   [Expand]Visual Elements
    Services
    Events
    Commands
    Keyboard Shortcuts
    HTML Tag Support
   [Collapse]Examples
    [Expand]Files
    [Expand]Text
    [Expand]Formatting
    [Expand]Styles
    [Expand]Lists
    [Expand]Pictures
    [Expand]Text Boxes
    [Expand]Tables
    [Expand]Document Elements
    [Expand]Layout
    [Collapse]Automation
      How to: Create a Table of Contents
      How to: Create a Table of Contents in Code
      How to: Add and Modify Fields
      How to: Handle the HyperlinkClick Event to Invoke the Custom Form
      How to: Retrieve the List of Document Fonts using the Visitor-Iterator Pattern
    [Expand]Search and Replace
    [Expand]Mail Merge
    [Expand]Spell Check
    [Expand]Export-Import
    [Expand]Printing
    [Expand]Protection
    [Expand]User Interface Customization
    [Expand]Commands
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Retrieve the List of Document Fonts using the Visitor-Iterator Pattern

You can use the DocumentIterator to retrieve all fonts used in the document and display them in the ListBoxControl, as shown below:

Follow the steps below to complete this task:

  1. Declare the DocumentVisitorBase class descendant. The DocumentVisitorBase implements the IDocumentVisitor interface. This interface provides the Visit method overloads for every document element type.

    Create the Fonts property to return the list of fonts retrieved by the Visitor.

    Override the corresponding IDocumentVisitor.Visit method to retrieve the DocumentText element 's ReadOnlyTextPropertiesBase.FontName value and add it to the fonts' list.

    Important

    You cannot remove the visited element's content or add new content.

  2. In the main class, declare a new Visitor class's object.

  3. Create a DocumentIterator class object. Pass true to the Iterator constructor as the visibleTextOnly parameter to skip hidden content.

  4. Call the DocumentIterator.MoveNext method to process each element, and use the IDocumentElement.Accept method to allow the Visitor to access the retrieved entity (returned by the DocumentIterator.Current property). When the iterator reaches the end of the document, the IDocumentElement.Accept method returns false. As a result, the Visitor executes the related Visit method for every iterated element.

    Pass one of the DocumentElementType values as a parameter to DocumentIterator.MoveNext method to check a specific type of elements.

  5. Pass the retrieved fonts' list as the BaseListBoxControl.DataSource property value to display the list the ListBoxControl.

  6. Some elements, such as DocumentTextBox or DocumentCommentElement, can contain other elements. Create a new visitor and iterator instance in the corresponding Visit method to get these entities' content. Use DocumentTextBox.GetIterator or DocumentCommentElement.GetIterator method to provide a new iterator with access to the element's content. Pass true as the method's visibleTextOnly parameter to skip hidden content.

    Note

    The iterator obtains only the main body's elements. The header's or footer's entities are not accessible to it.

Expanded See Also

Is this topic helpful?​​​​​​​