HtmlOptions to Use Alt Text instead of Images over All the PPT

I have a pptx file that I want to convert to HTML with removing all the images and replace them by their alt text(they are all set in the ppt)

Is that possible ? I don’t see the information in the doc.
I found this thread on Words : Possibility add alt text to images in converted html - #6 by tilal.ahmad . Is there the equivalent for slides?

Thanks in advance

@JeDeveloper,
Welcome to our community! Thank you for posting the query. This replacement may require all sorts of options to format output items. You could try to implement and use IHtmlFormattingController interface as shown below:

Presentation presentation = new Presentation("input.pptx");

HtmlOptions htmlOptions = new HtmlOptions();
HtmlImageFormattingController formattingController = new HtmlImageFormattingController();
htmlOptions.setHtmlFormatter(HtmlFormatter.createCustomFormatter(formattingController));

presentation.save("output.html", SaveFormat.Html, htmlOptions);
private class HtmlImageFormattingController implements IHtmlFormattingController
{
    @Override
    public void writeDocumentStart(IHtmlGenerator iHtmlGenerator, IPresentation iPresentation) {
    }

    @Override
    public void writeDocumentEnd(IHtmlGenerator iHtmlGenerator, IPresentation iPresentation) {
    }

    @Override
    public void writeSlideStart(IHtmlGenerator iHtmlGenerator, ISlide iSlide) {
    }

    @Override
    public void writeSlideEnd(IHtmlGenerator iHtmlGenerator, ISlide iSlide) {
    }

    @Override
    public void writeShapeStart(IHtmlGenerator iHtmlGenerator, IShape iShape) {
        if (iShape instanceof IPictureFrame)
        {
            IPictureFrame pictureFrame = (IPictureFrame) iShape;
            // implement your replacement here
        }
    }

    @Override
    public void writeShapeEnd(IHtmlGenerator iHtmlGenerator, IShape iShape) {
    }
}

API Reference: HtmlOptions Class, IHtmlFormattingController Interface

HI @Andrey_Potapov

Thanks for the quick response.

With the HtmlFormatter, I was able to add the alt Text :
iHtmlGenerator.addHtml("<img alt=" " + pictureFrame.getAlternativeText() + “” />");

But the image est still present? I try to delete it, by making it null (iShape=null;), to hide it, to set Width and Height to 0, but there seems to be a big placeholder still in place? (I have a giant white space in my html)
Is there anyway to delete it and it’s container after having added the alt text?

Thanks

@JeDeveloper,
In this case, as a workaround, I would suggest that you first prepare your presentations as shown below:

for (ISlide slide : presentation.getSlides()) {
    ArrayList<IPictureFrame> pictureFrames = new ArrayList<IPictureFrame>();

    for (IShape shape : slide.getShapes()) {
        if (shape instanceof IPictureFrame)                {
            pictureFrames.add((IPictureFrame)shape);
        }
    }

    for (IPictureFrame pictureFrame : pictureFrames) {
        String altText = pictureFrame.getAlternativeText();
        float x = pictureFrame.getX();
        float y = pictureFrame.getY();
        float width = pictureFrame.getWidth();
        float height = pictureFrame.getHeight();
        slide.getShapes().remove(pictureFrame);

        // add a shape with the desired view to the presentation here
    }
}

Then you can convert the presentation to HTML.

Also, I logged the issue with ID SLIDESJAVA-38626 in our tracking system. Our development team will consider skipping shapes by using the IHtmlFormattingController interface.

@Andrey_Potapov

Your code deletes the images, which is good. But the alt text is not shown, because when it reaches the HtmlFormatter, it has no more image. So i have either the image or nothing.

The goal is to replace the image with a <p>Text to replace the image</p> or a <img alt=“Text to replace”> as I mentionned earlier.
So if I understand correctly, it is not possible (at least for the moment) to replace image only by their alt text?

Thanks

@JeDeveloper,
I supposed that the above way would be used without the HTML formatting controller, and the shape with alt text and desired view instead of image would be added to the presentation by yourself.