Unable to Convert HTML Input Stream to PowerPoint Format in Java

Hi, I am trying to convert html input stream to pptx format, but I am seeing the following error

Convert failed - class com.aspose.slides.PptUnsupportedFormatException: Unknown file format. —> class com.aspose.slides.internal.da.int: Unknown file format._com.aspose.slides.internal.da.if.else(Unknown Source)_com.aspose.slides.internal.da.if.(Unknown Source)_com.aspose.slides.internal.da.new.new(Unknown Source)_com.aspose.slides.internal.da.new.for(Unknown Source)_com.aspose.slides.internal.da.new.(Unknown Source)_com.aspose.slides.internal.da.goto.do(Unknown Source)_com.aspose.slides.internal.da.goto.(Unknown Source)_com.aspose.slides.akd.if(Unknown Source)_com.aspose.slides.Presentation.do(Unknown Source)_com.aspose.slides.Presentation.if(Unknown Source)_com.aspose.slides.Presentation.(Unknown Source)_com.aspose.slides.Presentation.(Unknown Source)_sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)_sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

using the following code for the conversion

InputStream inputStream = new ByteArrayInputStream(temp.getBytes());
Presentation presentation = new Presentation(inputStream);
presentation.save(FILE_ABSOULTE_PATH + fileName + EXTENTION_PPT, SaveFormat.Ppt);

@rgutta,
Thank you for contacting support.

You can import the HTML document to a presentation. You should use the AddFromHtml method from the ISlideCollection interface as shown below:

var presentation = new Presentation();
var htmlStream = new FileInputStream("example.html");
presentation.getSlides().addFromHtml(htmlStream);
presentation.save("output.pptx", SaveFormat.Pptx);
presentation.dispose();
1 Like

Hi

I have tried the above approach but its only but the output presentation only contains text but does not have images. I have attached the html file I am using.Untitled-1.zip (481 Bytes)

@rgutta,
I am checking the problem you described and will get back to you soon.

@rgutta,
I’ve reproduced the problem with missing the image when importing the HTML document to a presentation and added a ticket with ID SLIDESJAVA-39091 to our issue-tracking system. We apologize for any inconvenience. Our development team will investigate the case. You will be notified when a new release of Aspose.Slides with a fix is published.

Hi Andrey,

Any update on the above issue.

@rgutta,
An investigation of the issue has been scheduled for the week 2023/06. Thank you for your patience.

The issues you found earlier (filed as SLIDESJAVA-39091) have been fixed in Aspose.Slides for Java 23.7 (JAR).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.

@rgutta,
Using Aspose.Slides for Java 23.7, please use the following code example:

Presentation presentation = new Presentation();
FileInputStream htmlStream = new FileInputStream(folderPath + "Untitled-1.html");
presentation.getSlides().addFromHtml(htmlStream, new ExternalHtmlResolver(), folderPath);
presentation.save(folderPath + "output.pptx", SaveFormat.Pptx);
presentation.dispose();
private static class ExternalHtmlResolver extends ExternalResourceResolver
{
    public java.io.InputStream getEntity(String absoluteUri)
    {
        try {
            URLConnection conn = new URL(absoluteUri).openConnection();
            boolean redirect = false;
            if (conn instanceof HttpURLConnection) {
                int status = ((HttpURLConnection) conn).getResponseCode();
                if (status != HttpURLConnection.HTTP_OK) {
                    if (status == HttpURLConnection.HTTP_MOVED_TEMP
                            || status == HttpURLConnection.HTTP_MOVED_PERM
                            || status == HttpURLConnection.HTTP_SEE_OTHER)
                        redirect = true;
                }
                if (redirect) {
                    String newUrl = conn.getHeaderField("Location");
                    String cookies = conn.getHeaderField("Set-Cookie");
                    conn = new URL(newUrl).openConnection();
                    conn.setRequestProperty("Cookie", cookies);
                }
            }
            try {
                return conn.getInputStream();
            } finally {
                if (conn.getInputStream() != null) conn.getInputStream().close();
                if (conn != null && conn instanceof HttpURLConnection) ((HttpURLConnection) conn).disconnect();
            }
        } catch (MalformedURLException e) {
            return null;
        } catch (IOException e) {
            return null;
        }
    }
}