Hi,
Is it possible to reduce the height and width of each slides before a presentation file is converted to an html ?
@pooja.jayan,
Thank you for your question.
To reduce the height and width of each presentation slide, you can change the slide size as shown below:
var scaleValue = 0.5f;
using (var presentation = new Presentation("example.pptx"))
{
var slideSize = presentation.SlideSize.Size;
var newSize = new SizeF(slideSize.Width * scaleValue, slideSize.Height * scaleValue);
presentation.SlideSize.SetSize(newSize.Width, newSize.Height, SlideSizeScaleType.EnsureFit);
presentation.Save("output.html", SaveFormat.Html);
}
Alternatively, you can scale the output HTML content like this:
var htmlOptions = new HtmlOptions
{
HtmlFormatter = HtmlFormatter.CreateCustomFormatter(new ScaleHtmlController())
};
using (var presentation = new Presentation("example.pptx"))
{
presentation.Save("output.html", SaveFormat.Html, htmlOptions);
}
class ScaleHtmlController : IHtmlFormattingController
{
public void WriteDocumentStart(IHtmlGenerator generator, IPresentation presentation)
{
}
public void WriteDocumentEnd(IHtmlGenerator generator, IPresentation presentation)
{
}
public void WriteShapeEnd(IHtmlGenerator generator, IShape shape)
{
}
public void WriteShapeStart(IHtmlGenerator generator, IShape shape)
{
}
public void WriteSlideStart(IHtmlGenerator generator, ISlide slide)
{
generator.AddHtml(m_slideStart);
}
public void WriteSlideEnd(IHtmlGenerator generator, ISlide slide)
{
generator.AddHtml(m_slideEnd);
}
private const string m_slideStart = "<div style=\"zoom: 0.5; -moz-transform: scale(0.5);\">\n";
private const string m_slideEnd = "</div>\n";
}
Documents:
Slide Size
Convert PowerPoint (PPT, PPTX) to HTML
API Reference:
ISlideSize interface
HtmlOptions class
HtmlFormatter class
IHtmlFormattingController interface
I tried with this code. But the size of the slides are getting reduced and also the contents get cuts off.
attaching the powerpoint file and output html generated
Files.zip (769.9 KB)
@pooja.jayan,
With Aspose.Slides for .NET 23.12, I was unable to reproduce the problem you described. My result:
output.zip (767.5 KB).
We recommend to you using the latest version of Aspose.Slides for .NET.
If the issue persists, please share the following information:
- OS version on which the conversion was performed
- .NET target platform in your app
- Aspose.Slides version you used
- OS version - Windows 10
- .NET - 3.1
- Aspose.Slides version - 22.8.0
I cannot upgrade to the latest version now. Can you check with the version I used.
@pooja.jayan,
With Aspose.Slides for .NET 22.8, I was also unable to reproduce the problem.
You can use a temporary license and check your results in a new project.
this works fine when I try to convert the whole file into html once.
But in my case, I want to convert each slide seperately into html file.
Presentation presentation = new Presentation(destFileName);
int count1 = 0;
for (int i = 0; i < presentation.Slides.Count; i++)
{
count1++;
using (MemoryStream pageStream = new MemoryStream())
{
// Save each page as a separate document.
//Page extractedPage = page;
Aspose.Slides.Presentation extractedPage = new Aspose.Slides.Presentation();
extractedPage.Slides.InsertClone(0, presentation.Slides[i]);
//extractedPage.ViewProperties.SlideViewProperties.Scale = 10;
HtmlOptions htmlOpt = new HtmlOptions();
var scaleValue = 0.5f;
var slideSize = extractedPage.SlideSize.Size;
var newSize = new SizeF(slideSize.Width * scaleValue, slideSize.Height * scaleValue);
extractedPage.SlideSize.SetSize(newSize.Width, newSize.Height, SlideSizeScaleType.EnsureFit);
extractedPage.Save(Path.Combine(path, $"output{count1}.html"), SaveFormat.Html);
}
}
I was using this code, with the same input file, and I have the issue here
@pooja.jayan,
Thank you for the additional information. I am working on the issue and will get back to you soon.
@pooja.jayan,
It looks like you should set the size for the slides before cloning them. Please use the followng code example:
using (var presentation = new Presentation(destFileName))
{
const float scaleValue = 0.5f;
var slideSize = presentation.SlideSize.Size;
var newSize = new SizeF(slideSize.Width * scaleValue, slideSize.Height * scaleValue);
for (int i = 0; i < presentation.Slides.Count; i++)
{
// Save each page as a separate document.
using (var extractedPage = new Presentation())
{
extractedPage.SlideSize.SetSize(newSize.Width, newSize.Height, SlideSizeScaleType.EnsureFit);
extractedPage.Slides.InsertClone(0, presentation.Slides[i]);
extractedPage.Save(Path.Combine(path, $"output{i + 1}.html"), SaveFormat.Html);
}
}
}