Dear Betsy,
Sorry I wasn't clear enough. We do not have system memory issues, but the size of the generated presentation on the hard drive issues.
Here are the code and a sample presentation.
- Code: Select all
Presentation testPresentation = new Presentation();
Presentation presentationFromDisk = new Presentation();
Presentation smallerPresentation = new Presentation();
Presentation largerPresentation = new Presentation();
string fileName = @"C:\SpireTest.pptx";
smallerPresentation.Slides.RemoveAt(0);
smallerPresentation.Masters.RemoveAt(0);
largerPresentation.Slides.RemoveAt(0);
largerPresentation.Masters.RemoveAt(0);
using (FileStream fs = File.Open(fileName, FileMode.Open))
{
presentationFromDisk.LoadFromStream(fs, FileFormat.Auto);
}
for (int i = 0; i < presentationFromDisk.Slides.Count; i++)
{
smallerPresentation.Slides.Append(presentationFromDisk.Slides[i]);
}
smallerPresentation.SaveToFile(@"C:\Result.pptx", FileFormat.Auto);
for (int i = 0; i < presentationFromDisk.Slides.Count; i++)
{
Presentation oneSlidePresentation = new Presentation();
oneSlidePresentation.Slides.RemoveAt(0);
oneSlidePresentation.Masters.RemoveAt(0);
oneSlidePresentation.Slides.Append(presentationFromDisk.Slides[i]);
largerPresentation.Slides.Append(oneSlidePresentation.Slides[0]);
}
largerPresentation.SaveToFile(@"C:\BadResult.pptx", FileFormat.Auto);
The resulting presentations are different in size, although seemingly the same in content. BadResult.pptx takes up several times more disk space than Result.pptx. This is because BadResult.pptx has more master slides than the Result.pptx. I know this specific code doesn't seem like a realistic scenario, but there are scenarios when you have to add slides from different presentations to the result, and the result becomes a large file. This is because every slide copies its master to the new presentation. I don't know if there is a way to remove unnecessary master slides or master slide layout components to reduce the size of the result. We've found a workaround for this issue for our project, but we wanted to notify you that this can become an potential issue.
If there is any need for additional clarification, feel free to ask.
All the best,
Dusan
Login to view the files attached to this post.