com.aspose.words

Interface IFontSavingCallback

  • public interface IFontSavingCallback 

Implement this interface if you want to receive notifications and control how Aspose.Words saves fonts when exporting a document to HTML format.

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() + "Rendering.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(getArtifactsDir() + "Document.SaveWithFontsExport.html", options);
}

/// <summary>
/// Prints information about fonts and saves them alongside their output .html
/// </summary>
public static class HandleFontSaving implements IFontSavingCallback {
    public void fontSaving(FontSavingArgs args) throws Exception {
        // Print information about fonts
        System.out.println(MessageFormat.format("Font:\t{0}", args.getFontFamilyName()));
        if (args.getBold()) System.out.println(", bold");
        if (args.getItalic()) System.out.println(", italic");
        System.out.println(MessageFormat.format("\nSource:\t{0}, {1} bytes\n", args.getOriginalFileName(), args.getOriginalFileSize()));

        Assert.assertTrue(args.isExportNeeded());
        Assert.assertTrue(args.isSubsettingNeeded());

        // We can designate where each font will be saved by either specifying a file name, or creating a new stream
        String[] parts = args.getOriginalFileName().split(File.separator + File.separator);
        String lastOne = parts[parts.length - 1];
        args.setFontFileName(lastOne);

        Assert.assertFalse(args.getKeepFontStreamOpen());
        // We can access the source document from here also
        Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.doc"));
    }
}

Method Summary
abstract voidfontSaving(FontSavingArgs args)
Called when Aspose.Words is about to save a font resource.
 

    • Method Detail

      • fontSaving

        public abstract void fontSaving(FontSavingArgs args)
                                     throws java.lang.Exception
        Called when Aspose.Words is about to save a font resource.

        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() + "Rendering.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(getArtifactsDir() + "Document.SaveWithFontsExport.html", options);
        }
        
        /// <summary>
        /// Prints information about fonts and saves them alongside their output .html
        /// </summary>
        public static class HandleFontSaving implements IFontSavingCallback {
            public void fontSaving(FontSavingArgs args) throws Exception {
                // Print information about fonts
                System.out.println(MessageFormat.format("Font:\t{0}", args.getFontFamilyName()));
                if (args.getBold()) System.out.println(", bold");
                if (args.getItalic()) System.out.println(", italic");
                System.out.println(MessageFormat.format("\nSource:\t{0}, {1} bytes\n", args.getOriginalFileName(), args.getOriginalFileSize()));
        
                Assert.assertTrue(args.isExportNeeded());
                Assert.assertTrue(args.isSubsettingNeeded());
        
                // We can designate where each font will be saved by either specifying a file name, or creating a new stream
                String[] parts = args.getOriginalFileName().split(File.separator + File.separator);
                String lastOne = parts[parts.length - 1];
                args.setFontFileName(lastOne);
        
                Assert.assertFalse(args.getKeepFontStreamOpen());
                // We can access the source document from here also
                Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.doc"));
            }
        }