Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved memory consumption for PresentationBuilder.PublishSlides #44

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions OpenXmlPowerTools/PowerPoint/FluentPresentationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ public void AppendSlides(PresentationDocument sourceDocument, int start, int cou
var newSlide = _newDocument.PresentationPart.AddNewPart<SlidePart>();
var slideDocument = slide.GetXDocument();

// cached annotation should be removed because it will be used in a new slide
slide.RemoveAnnotations<XDocument>();

// If we extract one slide, this slide should be visible
slideDocument.Root?.Attribute(NoNamespace.show)?.Remove();

Expand Down
11 changes: 6 additions & 5 deletions OpenXmlPowerTools/PowerPoint/PresentationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ public static IList<PmlDocument> PublishSlides(PmlDocument src)

public static IEnumerable<PmlDocument> PublishSlides(PresentationDocument srcDoc, string fileName)
{
var slideList = srcDoc.PresentationPart.GetXDocument().Root.Descendants(P.sldId).ToList();
for (var slideNumber = 0; slideNumber < slideList.Count; slideNumber++)
var slidesCount = srcDoc.PresentationPart.GetXDocument().Root.Descendants(P.sldId).Count();
for (var slideNumber = 0; slideNumber < slidesCount; slideNumber++)
{
using var streamDoc = OpenXmlMemoryStreamDocument.CreatePresentationDocument();
using (var output = streamDoc.GetPresentationDocument(new OpenSettings { AutoSave = false}))
using (var output = streamDoc.GetPresentationDocument(new OpenSettings { AutoSave = false }))
{
ExtractSlide(srcDoc, slideNumber, output);

var slidePartId = slideList.ElementAt(slideNumber).Attribute(R.id)?.Value;
var slidePart = (SlidePart)srcDoc.PresentationPart.GetPartById(slidePartId);
var slides = output.PresentationPart.GetXDocument().Root.Descendants(P.sldId);
var slidePartId = slides.ElementAt(0).Attribute(R.id)?.Value;
var slidePart = (SlidePart)output.PresentationPart.GetPartById(slidePartId);
output.PackageProperties.Title = PresentationBuilderTools.GetSlideTitle(slidePart);
}

Expand Down