com.aspose.words

Class FontInfoCollection

  • java.lang.Object
    • com.aspose.words.FontInfoCollection
  • All Implemented Interfaces:
    java.lang.Iterable
    public class FontInfoCollection 
    extends java.lang.Object

Represents a collection of fonts used in a document.

Items are FontInfo objects.

You do not create instances of this class directly. Use the DocumentBase.FontInfos property to access the collection of fonts defined in the document.

Example:

Shows how to save a document with embedded TrueType fonts
Document doc = new Document(getMyDir() + "Document.docx");

FontInfoCollection fontInfos = doc.getFontInfos();
fontInfos.setEmbedTrueTypeFonts(true);
fontInfos.setEmbedSystemFonts(false);
fontInfos.setSaveSubsetFonts(false);

doc.save(getMyDir() + "/Artifacts/Document.docx");

Example:

Shows how to gather the details of what fonts are present in a document.
Document doc = new Document(getMyDir() + "Document.doc");

FontInfoCollection fonts = doc.getFontInfos();
int fontIndex = 1;

// The fonts info extracted from this document does not necessarily mean that the fonts themselves are
// used in the document. If a font is present but not used then most likely they were referenced at some time
// and then removed from the Document.
for (FontInfo info : fonts)
{
    // Print out some important details about the font.
    System.out.println(MessageFormat.format("Font #{0}", fontIndex));
    System.out.println(MessageFormat.format("Name: {0}", info.getName()));
    System.out.println(MessageFormat.format("IsTrueType: {0}", info.isTrueType()));
    fontIndex++;
}
See Also:
FontInfo, DocumentBase.FontInfos

Property Getters/Setters Summary
intgetCount()
Gets the number of elements contained in the collection.
booleangetEmbedSystemFonts()
void
setEmbedSystemFonts(booleanvalue)
          

Specifies whether or not to embed System fonts into the document. Default value for this property is false.

This option works only when EmbedTrueTypeFonts option is set to true.

booleangetEmbedTrueTypeFonts()
void
setEmbedTrueTypeFonts(booleanvalue)
           Specifies whether or not to embed TrueType fonts in a document when it is saved. Default value for this property is false.
booleangetSaveSubsetFonts()
void
setSaveSubsetFonts(booleanvalue)
          

Specifies whether or not to save a subset of the embedded TrueType fonts with the document. Default value for this property is false.

This option works only when EmbedTrueTypeFonts property is set to true.

FontInfoget(int index)
Gets a font at the specified index.
FontInfoget(java.lang.String name)
Gets a font with the specified name.
 
Method Summary
booleancontains(java.lang.String name)
Determines whether the collection contains a font with the given name.
java.util.Iterator<FontInfo>iterator()
Returns an iterator object that can be used to iterate over all items in the collection.
 

    • Property Getters/Setters Detail

      • getCount

        public int getCount()
        
        Gets the number of elements contained in the collection.
      • getEmbedSystemFonts/setEmbedSystemFonts

        public boolean getEmbedSystemFonts() / public void setEmbedSystemFonts(boolean value)
        

        Specifies whether or not to embed System fonts into the document. Default value for this property is false.

        This option works only when EmbedTrueTypeFonts option is set to true.

        Setting this property to True is useful if the user is on an East Asian system and wants to create a document that is readable by others who do not have fonts for that language on their system. For example, a user on a Japanese system could choose to embed the fonts in a document so that the Japanese document would be readable on all systems.

        This option works for DOC, DOCX and RTF formats only.

        Example:

        Shows how to save a document with embedded TrueType fonts
        Document doc = new Document(getMyDir() + "Document.docx");
        
        FontInfoCollection fontInfos = doc.getFontInfos();
        fontInfos.setEmbedTrueTypeFonts(true);
        fontInfos.setEmbedSystemFonts(false);
        fontInfos.setSaveSubsetFonts(false);
        
        doc.save(getMyDir() + "/Artifacts/Document.docx");
      • getEmbedTrueTypeFonts/setEmbedTrueTypeFonts

        public boolean getEmbedTrueTypeFonts() / public void setEmbedTrueTypeFonts(boolean value)
        
        Specifies whether or not to embed TrueType fonts in a document when it is saved. Default value for this property is false.

        Embedding TrueType fonts allows others to view the document with the same fonts that were used to create it, but may substantially increase the document size.

        This option works for DOC, DOCX and RTF formats only.

        Example:

        Shows how to save a document with embedded TrueType fonts
        Document doc = new Document(getMyDir() + "Document.docx");
        
        FontInfoCollection fontInfos = doc.getFontInfos();
        fontInfos.setEmbedTrueTypeFonts(true);
        fontInfos.setEmbedSystemFonts(false);
        fontInfos.setSaveSubsetFonts(false);
        
        doc.save(getMyDir() + "/Artifacts/Document.docx");
      • getSaveSubsetFonts/setSaveSubsetFonts

        public boolean getSaveSubsetFonts() / public void setSaveSubsetFonts(boolean value)
        

        Specifies whether or not to save a subset of the embedded TrueType fonts with the document. Default value for this property is false.

        This option works only when EmbedTrueTypeFonts property is set to true.

        This option works for DOC, DOCX and RTF formats only.

        Example:

        Shows how to save a document with embedded TrueType fonts
        Document doc = new Document(getMyDir() + "Document.docx");
        
        FontInfoCollection fontInfos = doc.getFontInfos();
        fontInfos.setEmbedTrueTypeFonts(true);
        fontInfos.setEmbedSystemFonts(false);
        fontInfos.setSaveSubsetFonts(false);
        
        doc.save(getMyDir() + "/Artifacts/Document.docx");
      • get

        public FontInfo get(int index)
        
        Gets a font at the specified index.
        Parameters:
        index - Zero-based index of the font.
      • get

        public FontInfo get(java.lang.String name)
        
        Gets a font with the specified name.
        Parameters:
        name - Case-insensitive name of the font to locate.
    • Method Detail

      • contains

        public boolean contains(java.lang.String name)
        Determines whether the collection contains a font with the given name.
        Parameters:
        name - Case-insensitive name of the font to locate.
        Returns:
        True if the item is found in the collection; otherwise, false.
      • iterator

        public java.util.Iterator<FontInfo> iterator()
        Returns an iterator object that can be used to iterate over all items in the collection.