com.aspose.words

Interface IResourceSavingCallback

  • public interface IResourceSavingCallback 

Implement this interface if you want to control how Aspose.Words saves external resources (images, fonts and css) when saving a document to fixed page HTML or SVG.

Example:

Shows how used target machine fonts to display the document.
public void usingMachineFonts() throws Exception {
    Document doc = new Document(getMyDir() + "Font.DisappearingBulletPoints.doc");

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

    doc.save(getArtifactsDir() + "UseMachineFonts.html", saveOptions);
}

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) throws Exception {
        args.setResourceStream(new ByteArrayOutputStream());
        args.setKeepResourceStreamOpen(true);

        String fileName = args.getResourceFileName();
        String extension = fileName.substring(fileName.lastIndexOf("."));
        switch (extension) {
            case ".ttf":
            case ".woff":
                Assert.fail("'ResourceSavingCallback' is not fired for fonts when 'UseTargetMachineFonts' is true");
                break;
            }
        }
    }

Method Summary
abstract voidresourceSaving(ResourceSavingArgs args)
Called when Aspose.Words saves an external resource to fixed page HTML or SVG formats.
 

    • Method Detail

      • resourceSaving

        public abstract void resourceSaving(ResourceSavingArgs args)
                                         throws java.lang.Exception
        Called when Aspose.Words saves an external resource to fixed page HTML or SVG formats.

        Example:

        Shows how used target machine fonts to display the document.
        public void usingMachineFonts() throws Exception {
            Document doc = new Document(getMyDir() + "Font.DisappearingBulletPoints.doc");
        
            HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions();
            saveOptions.setUseTargetMachineFonts(true);
            saveOptions.setFontFormat(ExportFontFormat.TTF);
            saveOptions.setExportEmbeddedFonts(false);
            saveOptions.setResourceSavingCallback(new ResourceSavingCallback());
        
            doc.save(getArtifactsDir() + "UseMachineFonts.html", saveOptions);
        }
        
        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) throws Exception {
                args.setResourceStream(new ByteArrayOutputStream());
                args.setKeepResourceStreamOpen(true);
        
                String fileName = args.getResourceFileName();
                String extension = fileName.substring(fileName.lastIndexOf("."));
                switch (extension) {
                    case ".ttf":
                    case ".woff":
                        Assert.fail("'ResourceSavingCallback' is not fired for fonts when 'UseTargetMachineFonts' is true");
                        break;
                    }
                }
            }