com.aspose.words

Class FontSavingArgs

  • java.lang.Object
    • com.aspose.words.FontSavingArgs
public class FontSavingArgs 
extends java.lang.Object

When Aspose.Words saves a document to HTML or related formats and HtmlSaveOptions.ExportFontResources is set to true, it saves each font subject for export into a separate file.

FontSavingArgs controls whether particular font resource should be exported and how.

FontSavingArgs also allows to redefine how font file names are generated or to completely circumvent saving of fonts into files by providing your own stream objects.

To decide whether to save a particular font resource, use the IsExportNeeded property.

To save fonts into streams instead of files, use the FontStream property.

Example:

Shows how to define custom logic for handling font exporting when saving to HTML based formats.
public void saveHtmlExportFonts() throws Exception
{
    Document doc = new Document(getMyDir() + "Document.doc");

    // Set the option to export font resources.
    HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.MHTML);
    options.setExportFontResources(true);
    // Create and pass the object which implements the handler methods.
    options.setFontSavingCallback(new HandleFontSaving());

    doc.save(getMyDir() + "\\Artifacts\\Document.SaveWithFontsExport.html", options);
}

public class HandleFontSaving implements IFontSavingCallback
{
    public void fontSaving(FontSavingArgs args)
    {
        // You can implement logic here to rename fonts, save to file etc. For this example just print some details about the current font being handled.
        System.out.println(MessageFormat.format("Font Name = {0}, Font Filename = {1}", args.getFontFamilyName(), args.getFontFileName()));
    }
}

Property Getters/Setters Summary
booleangetBold()
Indicates whether the current font is bold.
DocumentgetDocument()
Gets the document object that is being saved.
java.lang.StringgetFontFamilyName()
Indicates the current font family name.
java.lang.StringgetFontFileName()
void
setFontFileName(java.lang.Stringvalue)
           Gets or sets the file name (without path) where the font will be saved to.
java.io.OutputStreamgetFontStream()
void
setFontStream(java.io.OutputStreamvalue)
           Allows to specify the stream where the font will be saved to.
booleanisExportNeeded()
void
isExportNeeded(booleanvalue)
           Allows to specify whether the current font will be exported as a font resource. Default is true.
booleanisSubsettingNeeded()
void
isSubsettingNeeded(booleanvalue)
           Allows to specify whether the current font will be subsetted before exporting as a font resource.
booleangetItalic()
Indicates whether the current font is italic.
booleangetKeepFontStreamOpen()
void
setKeepFontStreamOpen(booleanvalue)
           Specifies whether Aspose.Words should keep the stream open or close it after saving a font.
java.lang.StringgetOriginalFileName()
Gets the original font file name with an extension.
intgetOriginalFileSize()
Gets the original font file size.
 

    • Property Getters/Setters Detail

      • getBold

        public boolean getBold()
        
        Indicates whether the current font is bold.
      • getDocument

        public Document getDocument()
        
        Gets the document object that is being saved.
      • getFontFamilyName

        public java.lang.String getFontFamilyName()
        
        Indicates the current font family name.

        Example:

        Shows how to define custom logic for handling font exporting when saving to HTML based formats.
        public void saveHtmlExportFonts() throws Exception
        {
            Document doc = new Document(getMyDir() + "Document.doc");
        
            // Set the option to export font resources.
            HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.MHTML);
            options.setExportFontResources(true);
            // Create and pass the object which implements the handler methods.
            options.setFontSavingCallback(new HandleFontSaving());
        
            doc.save(getMyDir() + "\\Artifacts\\Document.SaveWithFontsExport.html", options);
        }
        
        public class HandleFontSaving implements IFontSavingCallback
        {
            public void fontSaving(FontSavingArgs args)
            {
                // You can implement logic here to rename fonts, save to file etc. For this example just print some details about the current font being handled.
                System.out.println(MessageFormat.format("Font Name = {0}, Font Filename = {1}", args.getFontFamilyName(), args.getFontFileName()));
            }
        }
      • getFontFileName/setFontFileName

        public java.lang.String getFontFileName() / public void setFontFileName(java.lang.String value)
        
        Gets or sets the file name (without path) where the font will be saved to.

        This property allows you to redefine how the font file names are generated during export to HTML.

        When the event is fired, this property contains the file name that was generated by Aspose.Words. You can change the value of this property to save the font into a different file. Note that file names must be unique.

        Aspose.Words automatically generates a unique file name for every embedded font when exporting to HTML format. How the font file name is generated depends on whether you save the document to a file or to a stream.

        When saving a document to a file, the generated font file name looks like <document base file name>.<original file name><optional suffix>.<extension>.

        When saving a document to a stream, the generated font file name looks like Aspose.Words.<document guid>.<original file name><optional suffix>.<extension>.

        FontFileName must contain only the file name without the path. Aspose.Words determines the path for saving using the document file name, the HtmlSaveOptions.FontsFolder and HtmlSaveOptions.FontsFolderAlias properties.

        Example:

        Shows how to define custom logic for handling font exporting when saving to HTML based formats.
        public void saveHtmlExportFonts() throws Exception
        {
            Document doc = new Document(getMyDir() + "Document.doc");
        
            // Set the option to export font resources.
            HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.MHTML);
            options.setExportFontResources(true);
            // Create and pass the object which implements the handler methods.
            options.setFontSavingCallback(new HandleFontSaving());
        
            doc.save(getMyDir() + "\\Artifacts\\Document.SaveWithFontsExport.html", options);
        }
        
        public class HandleFontSaving implements IFontSavingCallback
        {
            public void fontSaving(FontSavingArgs args)
            {
                // You can implement logic here to rename fonts, save to file etc. For this example just print some details about the current font being handled.
                System.out.println(MessageFormat.format("Font Name = {0}, Font Filename = {1}", args.getFontFamilyName(), args.getFontFileName()));
            }
        }
        See Also:
        FontStream, HtmlSaveOptions.FontsFolder, HtmlSaveOptions.FontsFolderAlias
      • getFontStream/setFontStream

        public java.io.OutputStream getFontStream() / public void setFontStream(java.io.OutputStream value)
        
        Allows to specify the stream where the font will be saved to.

        This property allows you to save fonts to streams instead of files during HTML export.

        The default value is null. When this property is null, the font will be saved to a file specified in the FontFileName property.

        See Also:
        FontFileName, KeepFontStreamOpen
      • isExportNeeded/isExportNeeded

        public boolean isExportNeeded() / public void isExportNeeded(boolean value)
        
        Allows to specify whether the current font will be exported as a font resource. Default is true.
      • isSubsettingNeeded/isSubsettingNeeded

        public boolean isSubsettingNeeded() / public void isSubsettingNeeded(boolean value)
        
        Allows to specify whether the current font will be subsetted before exporting as a font resource.

        Fonts can be exported as complete original font files or subsetted to include only the characters that are used in the document. Subsetting allows to reduce the resulting font resource size.

        By default, Aspose.Words decides whether to perform subsetting or not by comparing the original font file size with the one specified in HtmlSaveOptions.FontResourcesSubsettingSizeThreshold. You can override this behavior for individual fonts by setting the IsSubsettingNeeded property.

      • getItalic

        public boolean getItalic()
        
        Indicates whether the current font is italic.
      • getKeepFontStreamOpen/setKeepFontStreamOpen

        public boolean getKeepFontStreamOpen() / public void setKeepFontStreamOpen(boolean value)
        
        Specifies whether Aspose.Words should keep the stream open or close it after saving a font.

        Default is false and Aspose.Words will close the stream you provided in the FontStream property after writing a font into it. Specify true to keep the stream open.

        See Also:
        FontStream
      • getOriginalFileName

        public java.lang.String getOriginalFileName()
        
        Gets the original font file name with an extension.

        This property contains the original file name of the current font if it is known. Otherwise it can be an empty string.

        See Also:
        OriginalFileSize
      • getOriginalFileSize

        public int getOriginalFileSize()
        
        Gets the original font file size.

        This property contains the original file size of the current font if it is known. Otherwise it can be zero.

        See Also:
        OriginalFileName, IsSubsettingNeeded