public interface IFontSavingCallback
Example:
public void saveHtmlExportFonts() throws Exception {
Document doc = new Document(getMyDir() + "Rendering.docx");
// Set the option to export font resources and create and pass the object which implements the handler methods
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
options.setExportFontResources(true);
options.setFontSavingCallback(new HandleFontSaving());
// The fonts from the input document will now be exported as .ttf files and saved alongside the output document
doc.save(getArtifactsDir() + "Document.SaveHtmlExportFonts.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.docx"));
}
}
Method Summary | ||
---|---|---|
abstract void | fontSaving(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 |
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.docx"); // Set the option to export font resources and create and pass the object which implements the handler methods HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML); options.setExportFontResources(true); options.setFontSavingCallback(new HandleFontSaving()); // The fonts from the input document will now be exported as .ttf files and saved alongside the output document doc.save(getArtifactsDir() + "Document.SaveHtmlExportFonts.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.docx")); } }