PowerPoint to HTML5 Conversion in C# Does Not Work as Expected

@samirka,
Could you please specify in which programming language you would like to use Aspose.Slides?

@andrey.potapov It’s going to be either Java or .Net. Right now .Net6 requires some additional libraries if not executed on Windows (and on Mac with Apple silicon I can’t even get Aspose.Slides to run at all since the MacOS Gatekeeper seeing libaspose.slides.drawing.capi_appleclang_arm64.dylib as malicious software). So Java looks like the only valid choice for now. However if .Net Aspose.Slides will somehow start working on Mac then .Net might be a valid choice as well.

Thanks

@samirka,
Once the problems you found are resolved in Aspose.Slides for .NET, they will be resolved in the same version of Aspose.Slides for Java.

Could you please indicate which version of Aspose.Slides for .NET you used?

@andrey.potapov I’ve been testing with the latest version available 23.12 (both .Net and Java)

@samirka,
You can try using Aspose.Slides for .NET Standard on macOS. This target version of Aspose.Slides is included in Aspose.Slides for .NET package.

@andrey.potapov I could not get working on my Mac. The error I was getting was related to System.Drawing.Common library not be supported in this platform. Even Microsoft is saying it’s not going to be supported and needs to be migrated to some different libraries:

https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only

And thus I was using the following approach listed on your own site:
https://releases.aspose.com/slides/net/release-notes/2023/aspose-slides-for-net-23-6-release-notes/#net-6-nuget-depends-on-systemdrawingcommon-a-cross-platform-version-is-available-in-the-zip-and-msi-releases, which as I was saying was triggering security issue on my Mac

Unless there is some other solution I’m not aware of, .Net version does not work. Please test that yourself I’m pretty sure you’ll get the same result

Thanks

@samirka,
As I can see, you used Aspose.Slides for .NET 6. Could you please check your results using Aspose.Slides for .NET Standard 2.1? Please take a look at the NuGet and ZIP Packages section here:

@andrey.potapov Thanks, I’ll try that. Just to make sure .Net6 and onwards (.Net7 & .Net8) are not supported right now, right? Because I tried .Net8 and the result was the same. Let me try .Net Standard 2.1 as you have suggested. Will let you know the outcome shortly.

In addition are there any plans to migrate System.Drawing.Common going forward? There are many new feature that have been added since 2.1 so it would be nice to take advantage of that as well.

Thanks

@andrey.potapov I was not able to run the test as suggested on .net standard 2.1. Since I have .Net6 and .Net8 installed on my Mac, the project. file I was setting to:

<TargetFrameworks>netstandard2.1;net6.0</TargetFrameworks>

and this is what I was getting:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at.(Font )
   at.(String , ,  , Boolean , Int32 , & )
   at.( , ,  ,  ,  , Int32 , Boolean ,  , &)
   at .(& , Boolean&)
   at .()
   at ..ctor(TextFrame , , IBaseSlide , , [] )
   at .( , )
   at .( , Single, Single ,  )
   at .( , &, RectangleF& ,  )
   at .()
   at Aspose.Slides.Paragraph.GetRect()
   at (TextFrame , AutoShape)
   at .(TextFrame )
   at .()
   at [T](String , TemplateContext`1, TextWriter )
   at .[T](TextWriter , String, TemplateContext`1 )
   at.()
   at [T](String , TemplateContext`1, TextWriter )
   at .[T](TextWriter , String, TemplateContext`1 )
   at .(IShape , Slide, Boolean , Int32 , Dictionary`2 )
   at .()
   at [T](String , TemplateContext`1, TextWriter )
   at .()
   at .Compile(String , Object)
   at .Write(Stream )
   at .Save(String , IOutputFile)
   at Aspose.Slides.Export.Web.WebDocument.Save()
   at .(Presentation , Stream, IHtml5Options )
   at Aspose.Slides.Presentation.Save(Stream stream, SaveFormat format, ISaveOptions options)
   at Aspose.Slides.Presentation.Save(String fname, SaveFormat format)

I was referencing Aspose.Slides as a Nuget package.
Anyway, this what I meant with Java package just working in comparison with .Net

Thanks,

@samirka,

Cross-platform Aspose.Slides for .NET 6 can be used for .NET 7 and future .NET releases. Please take a look at this article.

Aspose.Slides for .NET NuGet package contains an assembly for .NET 6 that depends on System.Drawing.Common (for Windows only). Aspose.Slides for .NET ZIP and MSI packages contain the same and additionally, cross-platform version that does not depend on System.Drawing.Common.

Please also try using the following package:

@andrey.potapov that did the trick, thank you!

@andrey.potapov While I’m able to tun the code right now, I’m curious why cross platform Nuget package is not the same version as the the main one 23.11 vs 23.12. According to the release notes there are rather important bugfixes in the latest version: https://releases.aspose.com/slides/net/release-notes/2023/aspose-slides-for-net-23-12-release-notes/

2 posts were split to a new topic: Is There an Easy Way to Find Out If PowerPoint Needs to Be Converted to HTML5 Due To Either Video, Audio or Some Animation?

@samirka,
The cross-platform NuGet package is not the same version as the the main one because we found some issues with Docker. Aspose.Slides.NET6.CrossPlatform 23.12 will be published later. We apologize for any inconvenience.

@andrey.potapov understood, thanks for the explanation

@samirka,
Thank you for evaluating Aspose.Slides.

Hi @andrey.potapov, while evaluating Aspose.Slides I’ve identified another issue while converting PowerPoint file to HTML5. Please take a look at the included files. I’m using Aspose.Slides Aspose.Slides.NET6.CrossPlatform v23.11.

SamplePPTFile.HTML5.zip (32.7 KB)
SamplePPTFile.pptx.zip (37.3 KB)

The code is the same as listed above.

Thanks

@samirka,

I noticed drawing shapes missing and contents were not rendered properly in PPTX to HTML5.

We need to evaluate the issue in details. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESNET-44382

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@samirka,
At the moment, the simplest way to fix the page size in the output HTML is to insert the following script into the HTML file before the </body> tag:

    <script>

        // hide navigation buttons
        document.getElementById('PrevSlide').style.visibility = 'hidden';
        document.getElementById('NextSlide').style.visibility = 'hidden';

        // turn body position into flex
        var body = document.getElementsByTagName('body')[0];
        body.style.display = 'flex';
        body.style.justifyContent = 'center';
        body.style.alignItems = 'center';

        // store initial slide width and height
        var bg = document.getElementsByClassName('bg')[0];
        var initx = bg.getBoundingClientRect().width;
        var inity = bg.getBoundingClientRect().height;                

        // resize handler
        var onresize = function()
        {
            // calculate and apply transform
            var kx = window.innerWidth / initx;
            var ky = window.innerHeight / inity;
            bg.style.transform = `scale(${(kx <= ky) ? kx : ky})`;
        };

        // attach event handler
        window.onresize = onresize;

        // process initial resize
        onresize();

    </script>

You can do it while converting the presentation, for example, this way:

// Convert the presentation.
using (Presentation pres = new Presentation("MongoDB_pt.pptx"))
{
    pres.Save("MongoDB_pt.html", SaveFormat.Html5, new Html5Options
    {
        AnimateShapes = true,
        AnimateTransitions = true
    });
}

// The script mentioned above.
string script =
    "<script> document.getElementById('PrevSlide').style.visibility = 'hidden'; " +
    "document.getElementById('NextSlide').style.visibility = 'hidden'; " +
    "var body = document.getElementsByTagName('body')[0]; body.style.display = 'flex'; " +
    "body.style.justifyContent = 'center'; body.style.alignItems = 'center'; " +
    "var bg = document.getElementsByClassName('bg')[0]; var initx = bg.getBoundingClientRect().width; " +
    "var inity = bg.getBoundingClientRect().height; var onresize = function() { " +
    "var kx = window.innerWidth / initx; var ky = window.innerHeight / inity; " +
    "bg.style.transform = `scale(${(kx <= ky) ? kx : ky})`;}; window.onresize = onresize; " +
    "onresize();</script>\r\n</body>";

// Patch the result HTML file.
string htmlContent = File.ReadAllText("MongoDB_pt.html");
string newHtmlContent = htmlContent.Replace("</body>", script);
File.WriteAllText("MongoDB_pt.html", newHtmlContent);

Or you can use WebExtensions and edit the corresponding template file.

The issues you found earlier (filed as SLIDESNET-44382,SLIDESNET-44367,SLIDESNET-44366) have been fixed in Aspose.Slides for .NET 24.2 (ZIP, MSI).
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.