com.aspose.words

Class ExportFontFormat

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

Utility class containing constants. Indicates the format that is used to export fonts while rendering to HTML fixed format.

Example:

Shows how used target machine fonts to display the document.
public void usingMachineFonts() throws Exception {
    Document doc = new Document(getMyDir() + "Bullet points with alternative font.docx");

    HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions();
    {
        saveOptions.setExportEmbeddedCss(true);
        saveOptions.setUseTargetMachineFonts(true);
        saveOptions.setFontFormat(ExportFontFormat.TTF);
        saveOptions.setExportEmbeddedFonts(false);
        saveOptions.setResourceSavingCallback(new ResourceSavingCallback());
    }

    doc.save(getArtifactsDir() + "HtmlFixedSaveOptions.UsingMachineFonts.html", saveOptions);

    String outDocContents = FileUtils.readFileToString(new File(getArtifactsDir() + "HtmlFixedSaveOptions.UsingMachineFonts.html"), "utf-8");

    if (saveOptions.getUseTargetMachineFonts())
        Assert.assertFalse(outDocContents.matches("@font-face"));
    else
        Assert.assertTrue(outDocContents.matches("@font-face * font-family:'Arial'; font-style:normal; font-weight:normal; src:local[(]'☺'[)], " +
                "url[(]'HtmlFixedSaveOptions.UsingMachineFonts/font001.ttf'[)] format[(]'truetype'[)]; }"));
}

private static class ResourceSavingCallback implements IResourceSavingCallback {
    /**
     * Called when Aspose.Words saves an external resource to fixed page HTML or SVG.
     */
    public void resourceSaving(final ResourceSavingArgs args) {
        System.out.println(MessageFormat.format("Original document URI:\t{0}", args.getDocument().getOriginalFileName()));
        System.out.println(MessageFormat.format("Resource being saved:\t{0}", args.getResourceFileName()));
        System.out.println(MessageFormat.format("Full uri after saving:\t{0}", args.getResourceFileUri()));

        args.setResourceStream(new ByteArrayOutputStream());
        args.setKeepResourceStreamOpen(true);

        String extension = FilenameUtils.getExtension(args.getResourceFileName());
        switch (extension) {
            case "ttf":
            case "woff":
                Assert.fail("'ResourceSavingCallback' is not fired for fonts when 'UseTargetMachineFonts' is true");
                break;
        }
    }
}
See Also:
HtmlFixedSaveOptions.FontFormat

Field Summary
static final intWOFF = 0
WOFF (Web Open Font Format).
static final intTTF = 1
TTF (TrueType Font format).
 

    • Field Detail

      • WOFF = 0

        public static final int WOFF
        WOFF (Web Open Font Format).
      • TTF = 1

        public static final int TTF
        TTF (TrueType Font format).