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