We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Converting from DOCX to PPTX

Hi,

I’ve installed Aspose.Total & have applied temporary license of the same in my .NET project. I have a requirement to convert DOCX file into a PPTX file.
I’ve tried the sample code from Aspose DOCX To PPT Conversion

Included few logics to split each page in word document into separate HTML files & then converted it into PPTX file.

But I see that the tables, shapes & images aren’t retained in the PPT, though the HTML has it all from the Word document. Is there a way that the PPT could mirror everything that the HTML has?

Please let me know if I’m missing something. Here’s my C# code for your reference:

public static void ConvertWordToPPT()
{
    var license = new License();
    using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ConsoleApp2.Aspose.Total.NET.lic"))
    {
        license.SetLicense(stream);
    }

    Aspose.Words.Document docx = new Aspose.Words.Document("Rendering.docx");
    Presentation pres = new Presentation();
    // To convert multi pages DOCX documents, export each page to HTML separately using Aspose.Words and then use the below code to convert to PPT.
    int pageCount = docx.PageCount;
    for (int page = 0; page < pageCount; page++)
    {
        // Save each page as a separate document.
        Aspose.Words.Document extractedPage = docx.ExtractPages(page, 1);
        extractedPage.Save($"SplitDocument.PageByPage_{page + 1}.docx");
        // Save DOCX file to HTML 
        extractedPage.Save($"SplitDocument.PageByPage_{page + 1}.html", Aspose.Words.SaveFormat.Html);


        //Render data from html to a slide
        ILayoutSlide layoutSlide = pres.Slides[0].LayoutSlide;
        ISlide slide = pres.Slides.AddEmptySlide(layoutSlide);

        // Adding the AutoShape to accomodate the HTML content 
        // Adjust it as of your need
        IAutoShape ashape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 10, 10, pres.SlideSize.Size.Width - 20, pres.SlideSize.Size.Height - 10);

        ashape.FillFormat.FillType = FillType.NoFill;

        // Adding text frame to the shape
        ashape.AddTextFrame("");

        // Clearing all paragraphs in added text frame
        ashape.TextFrame.Paragraphs.Clear();

        // Loading the HTML file using stream reader
        TextReader tr = new StreamReader($"SplitDocument.PageByPage_{page + 1}.html");

        // Adding text from HTML stream reader in text frame
        ashape.TextFrame.Paragraphs.AddFromHtml(tr.ReadToEnd());


        foreach (var paragraph in ashape.TextFrame.Paragraphs)
            foreach (var portion in paragraph.Portions)
                portion.PortionFormat.FillFormat.FillType = FillType.Solid;
    }

    // Save the PPT Presentation
    pres.Save("pres.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}

Attached are my test input & output files. AsposeSamples.zip (113.4 KB)

Thanks,
Nivedhitha

@niverajkumar,
Thank you for describing the issue.

As for Aspose.Slides, I reproduced the problems while importing HTML documents to a PowerPoint presentation.

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-43782

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.

I also found some issues while converting the Word document to HTML files. My colleagues from Aspose.Words team will check them.

Please also share the following additional information:

  • OS version on which the code was executed
  • .NET target platform in your app
  • Aspose.Slides and Aspose.Words versions you used

Hi Andrey,

Thanks for the quick response!

Here’s the information that you needed:

  • OS version on which the code was executed: Windows 10
  • .NET target platform in your app: Am currently trying this on .NET Framework 4.7.2 & we might want this to work on .NET Core 3.1 & higher versions too.
  • Aspose.Slides and Aspose.Words versions you used: I used Aspose.Total (Aspose.Slides: 23.1.0.0 & Aspose.Words: 22.12.0.0)

Thanks,
Nivedhitha

@niverajkumar,
Thank you for the additional information. I forwarded it to our developers.