How to Save Images from PPTX Slides on a Disk when Converting to HTML in Java?

When I try to convert pptx to html, it convert the images to base64 in html but I want the images to be stored on a local disk here is the sample code I am using to convert/

ByteArrayOutputStream stream = new ByteArrayOutputStream();
Presentation presentation = new Presentation(fileName);
presentation.save(stream, SaveFormat.Html);
presentation.dispose();

@rgutta,
Thank you for posting your requirements.

Unfortunately, Aspose.Slides does not provide such a feature. I’ve linked this forum thread to an appropriate task with ID SLIDESJAVA-38959 in our issue-tracking system. You will be notified when a new release of Aspose.Slides with this feature is published.

@rgutta,
Our developers have investigated the case. Please try using the following code snippet:

public void main() {
    Presentation presentation = new Presentation(presPath);
    HtmlOptions htmlOptions = new HtmlOptions(new LinkController(resourcesOutputPath));
    htmlOptions.setSlideImageFormat(SlideImageFormat.svg(new SVGOptions()));
    // This line is needed to remove the slide title display in HTML.
    // Comment it out if your prefer slide title displayed.
    htmlOptions.setHtmlFormatter(HtmlFormatter.createDocumentFormatter("", false));

    System.out.println("Starting export");
    presentation.save("output.html", SaveFormat.Html, htmlOptions);
}
class LinkController implements ILinkEmbedController
{

    /// <summary>
    /// Default parameterless constructor
    /// </summary>
    public LinkController()
    {
        m_externalImages = new HashMap<>();
        s_templates.put("image/jpeg", "image-%d.jpg");
        s_templates.put("image/png", "image-%d.png");
    }

    /// <summary>
    /// Creates a class instance and sets the path where generated resource files will be saved to.
    /// </summary>
    /// <param name="savePath">Path to the location where generated resource files will be stored.</param>
    public LinkController(String savePath)
    {
        this();
        setSavePath(savePath);
    }

    public int getObjectStoringLocation(int id, byte[] entityData, String semanticName,
                                        String contentType,
                                        String recomendedExtension)
    {
        // Here we make the decision about storing images externally.
        // The id is unique identifier of each object during the whole export operation.
        String template;

        // The s_templates dictionary contains content types we are going to store externally and the corresponding file name template.
        if (s_templates.containsKey(contentType))
        {
            template = s_templates.get(contentType);
            // Storing this resource to the export list
            m_externalImages.put(id, template);
            return LinkEmbedDecision.Link;
        }

        // All other resources, if any, will be embedded
        return LinkEmbedDecision.Embed;
    }

    public String getUrl(int id, int referrer)
    {
        // Here we construct the resource reference string to form the tag: <img src="%result%">
        // We need to check the dictionary to filter out unnecessary resources.
        // Along with checking we extract the corresponding file name template.
        String template;
        if (m_externalImages.containsKey(id))
        {
            template = m_externalImages.get(id);
            // Assuming we are going to store resource files just near the HTML file.
            // The image tag will look like <img src="image-1.png"> with the appropriate resource Id and extension.
            String fileUrl = String.format(template, id);
            return fileUrl;
        }

        // null must be returned for the resources remaining embedded
        return null;
    }

    public void saveExternal(int id, byte[] entityData)
    {
        // Here we actually save the resource files to disk.
        // Once again, checking the dictionary. If the id is not found here it is a sign of an error in GetObjectStoringLocation or GetUrl methods.
        if (m_externalImages.containsKey(id))
        {
            // Now we use the file name stored in the dictionary and combine it with a path as required.

            // Constructing the file name using the stored template and the Id.
            String fileName = String.format(m_externalImages.get(id), id);

            // Combining with the location directory
            String filePath = (getSavePath() == null ? "" : getSavePath()) + fileName;

            try {
                FileOutputStream fs = new FileOutputStream(filePath);
                fs.write(entityData, 0, entityData.length);
                fs.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        else
            throw new RuntimeException("Something is wrong");
    }

    public String getSavePath()
    {
        return savePath;
    }

    public void setSavePath(String value)
    {
        savePath = value;
    }

    private String savePath;

    /**
     * A dictionary to store associations between resource ids and corresponding file names.
     */
    private final Map<Integer, String> m_externalImages;

    /**
     * A dictionary to store associations between content types of resources we are going to store externally
     * and corresponding file name templates.
     */
    private final Map<String, String> s_templates = new HashMap<>();
}

API Reference: ILinkEmbedController interface