PPT Document Is Not Like Original DOCX Document Using Aspose.Words and Aspose.Slides

I’m trying to set up some code to convert a Docx file into a pptx. I found this example on the aspose site
https://products.aspose.com/total/net/conversion/docx-to-ppt/

I added a variation of the code in the example and that didn’t work, so I created a stand alone project using a very simple word document and it still doesn’t work.
It does generate a PPT document but it is nothing like the original.

We have a license for Words already but I was using a trial version of Slides to test this. Not sure if that could be causing the issues?

I have attached the stand alone project to this ticket, any help/advice would be appreciated.

The project is too large to upload with both Words and Slides so I have uploaded it to dropbox and the link is - Dropbox - AsposeDocxToPPT_ASP.zip - Simplify your life

If that doesn’t work please let me know.

@josephallison there is not easy or direct way to convert DOCX to PPTX, but looks like thee bigger issue that you are facing is to load the HTML in the Slide, so I’m redirecting your query to Aspose.Slides forum where you receive proper guidance.

@josephallison,
Please share your output HTML and PPT files created by the application you provided.

I have uploaded the output directory for the application - DocxToPPTX_Output.zip (1.5 MB)

Base template is “SU_accred_workbook.docx”
then the output is “SU_accred_workbook.ppt”
the rest is the html that is generated when running the conversion

@josephallison,
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-43866

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’ve moved this forum thread to Aspose.Total forum. My colleagues from Aspose.Words team will also work on the issues related to DOCX to HTML conversion.

As a workaround, you can try DOCX to SVG to PPT conversion. The result will be much better.

Hi Andrey,

Is the “DOCX to SVG to PPT conversion” part of the aspose.Words code or is this in aspose.Slides?

Thanks

@josephallison,
You can use Aspose.Words to convert Word document pages to SVG images like this:

var options = new Aspose.Words.Saving.SvgSaveOptions
{
    PageSet = new Aspose.Words.Saving.PageSet(0)
};

var doc = new Aspose.Words.Document("example.docx");
doc.Save("image.svg", options);

API Reference: SvgSaveOptions Class

Using Aspose.Slides, you can add the SVG images to presentation slides like this:

using (var ppt = new Presentation())
{
    var svgContent = File.ReadAllText("image.svg");
    var svgImage = new SvgImage(svgContent);

    var pptImage = ppt.Images.AddImage(svgImage);

    ppt.SlideSize.SetSize(
        pptImage.Width, pptImage.Height, SlideSizeScaleType.DoNotScale);

    ppt.Slides[0].Shapes.AddPictureFrame(
        ShapeType.Rectangle, 0, 0, pptImage.Width, pptImage.Height, pptImage);

    ppt.Save("output.pptx", SaveFormat.Pptx);
}

Documents: Adding SVG to Presentations

Hi Andrey,

Thanks for the reply, is there anyway to do this in memory stream?

I have adjusted the first part of the code to inport a template/save it to memory stream but I’m unsire how to use this stream when converting to a SVG string?

The line:

var svgContent = File.ReadAllText("image.svg");

uses a hardcoded location/filename, but I do not wish to save the svg, so I would only have this in memory stream.

Aspose.Words.Document doc;
Stream stream = new MemoryStream(File.ReadAllBytes("**Some file path**\\template.docx"));

MemoryStream input = new MemoryStream();

var options = new Aspose.Words.Saving.SvgSaveOptions
{
    PageSet = new Aspose.Words.Saving.PageSet(0)
};

doc = new Aspose.Words.Document(stream);
doc.Save(input, options);

using (var ppt = new Aspose.Slides.Presentation())
{
    var svgContent = File.ReadAllText("image.svg");

    var svgImage = new SvgImage(svgContent);

    var pptImage = ppt.Images.AddImage(svgImage);

    ppt.SlideSize.SetSize(
        pptImage.Width, pptImage.Height, SlideSizeScaleType.DoNotScale);

    ppt.Slides[0].Shapes.AddPictureFrame(
        ShapeType.Rectangle, 0, 0, pptImage.Width, pptImage.Height, pptImage);

    ppt.Save("**Some file path**\\output.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}

@josephallison,
You can replace the code lines

var svgContent = File.ReadAllText("image.svg");
var svgImage = new SvgImage(svgContent);

with

input.Seek(0, SeekOrigin.Begin);
var svgImage = new SvgImage(input);

If it is not what you mean, please describe the issue you encountering in more detail.

Sorry I probably wasn’t clear enough, I am trying to pass in a Docx template and output a Pptx file.

It seems from my first issue this might not be possible so as you suggested im trying to convert the Docx to SVG then inserting that into a Pptx.

I would like to do this all in memory, I don’t want to save the SVG to the file system.

Aspose.Words.Document doc;
Stream stream = new MemoryStream(File.ReadAllBytes("C:\\Users\\JosephAllison\\Desktop\\SU_accred_workbook.docx"));

MemoryStream input = new MemoryStream();

var options = new Aspose.Words.Saving.SvgSaveOptions
{
    PageSet = new Aspose.Words.Saving.PageSet(0)
};

doc = new Aspose.Words.Document(stream);
doc.Save(input, options);

using (var ppt = new Aspose.Slides.Presentation())
{
    var svgContent = File.ReadAllText("image.svg");
    var svgImage = new SvgImage(svgContent);

    var pptImage = ppt.Images.AddImage(svgImage);

    ppt.SlideSize.SetSize(
        pptImage.Width, pptImage.Height, SlideSizeScaleType.DoNotScale);

    ppt.Slides[0].Shapes.AddPictureFrame(
        ShapeType.Rectangle, 0, 0, pptImage.Width, pptImage.Height, pptImage);

    ppt.Save("C:\\Users\\JosephAllison\\Desktop\\output.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}  

I am having an issue saving the SVG to memory as my first issue, it errors on the following line
doc.Save(input, options);
It returns an error stating
Resource file(s) cannot be written to disk. When saving the document to a stream either ResourceFolder should be specified or ExportEmbeddedImages, ExportEmbeddedFonts, ExportEmbeddedCss, and ExportEmbeddedSvg should be set or custom streams should be provided via ResourceSavingCallback.

So is it not possible to save SVG directly to a memory stream?

I found this ticket talking about the same issue - Re: doc to html
and it seems I might have to save the SVG to the file system before using it in the Pptx, is this correct?

@josephallison,
I reproduced the same error when saving the Word page to an SVG image using Aspose.Words.

@alexey.noskov, please pay attention.

@josephallison You should specify SvgSaveOptions.ExportEmbeddedImages option. For example see the following code:

SvgSaveOptions opt = new SvgSaveOptions();
opt.ExportEmbeddedImages= true;
opt.PageSet = new PageSet(0);

Document doc = new Document(@"C:\Temp\in.docx");
using (MemoryStream svgStream = new MemoryStream())
{
    doc.Save(svgStream, opt);
    // ...................
}

Thank you that now works, however the code only seems to generate one page in the output.

Does the Docx to SVG not save the whole document? Or do I need to save each page individually then add each SVG to a new slide?

Or is this a restriction of the trial license?

@josephallison Remove this line of code:

opt.PageSet = new PageSet(0);

In this case Aspose.Words will save all pages of the document to a single SVG. But I think in your case saving page by page will be more convenient to convert them to slides:

SvgSaveOptions opt = new SvgSaveOptions();
opt.ExportEmbeddedImages = true;

Document doc = new Document(@"C:\Temp\in.docx");

for (int i = 0; i < doc.PageCount; i++)
{
    opt.PageSet = new PageSet(i);

    using (MemoryStream svgStream = new MemoryStream())
    {
        doc.Save(svgStream, opt);
        // ...................
        // Convert page to slide
    }
}

In trial version Aspose.Words limits the maximum document size to several hundreds of paragraphs. You can request a 30-days free temporary license to test Aspose.Words and Aspose.Slides without evaluation version limitations.

The issues you found earlier (filed as SLIDESNET-43866) have been fixed in Aspose.Slides for .NET 23.7 (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.