com.aspose.words

Interface IImageSavingCallback

  • public interface IImageSavingCallback 

Implement this interface if you want to control how Aspose.Words saves images when saving a document to HTML. May be used by other formats.

Example:

Shows how to define custom logic for controlling how images are saved when exporting to HTML based formats.
public void saveHtmlExportImages() throws Exception
{
    Document doc = new Document(getMyDir() + "Document.doc");

    // Create and pass the object which implements the handler methods.
    HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
    options.setImageSavingCallback(new HandleImageSaving());

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

public class HandleImageSaving implements IImageSavingCallback
{
    public void imageSaving(ImageSavingArgs args) throws Exception
    {
        // Change any images in the document being exported with the extension of "jpeg" to "jpg".
        if (args.getImageFileName().endsWith(".jpeg"))
            args.setImageFileName(args.getImageFileName().replace(".jpeg", ".jpg"));
    }
}

Method Summary
abstract voidimageSaving(ImageSavingArgs args)
Called when Aspose.Words saves an image to HTML.
 

    • Method Detail

      • imageSaving

        public abstract void imageSaving(ImageSavingArgs args)
                                      throws java.lang.Exception
        Called when Aspose.Words saves an image to HTML.

        Example:

        Shows how to define custom logic for controlling how images are saved when exporting to HTML based formats.
        public void saveHtmlExportImages() throws Exception
        {
            Document doc = new Document(getMyDir() + "Document.doc");
        
            // Create and pass the object which implements the handler methods.
            HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
            options.setImageSavingCallback(new HandleImageSaving());
        
            doc.save(getMyDir() + "\\Artifacts\\Document.SaveWithCustomImagesExport.html", options);
        }
        
        public class HandleImageSaving implements IImageSavingCallback
        {
            public void imageSaving(ImageSavingArgs args) throws Exception
            {
                // Change any images in the document being exported with the extension of "jpeg" to "jpg".
                if (args.getImageFileName().endsWith(".jpeg"))
                    args.setImageFileName(args.getImageFileName().replace(".jpeg", ".jpg"));
            }
        }