'Copy slide containing notes from one PowerPoint presentaition to another with OpenXML SDK
I am trying to copy slides from one PowerPoint presentation to another. I have used the procedure outlined in the following article, and it generally works fine.
However, when the slide to be copied contains notes, the resulting presentation after copying is corrupted. I've noticed that the code generates a new notesMaster which is not added to the notesMasterIdLst in presentation.xml, and have a suspicion this might be the issue. However, I cannot add the new notes master to the presentation, as a presentation can only have one notesMaster.
Solution 1:[1]
According to the Microsoft Documentation, Open XML SDK is defined this way:
The Open XML SDK 2.5 simplifies the task of manipulating Open XML packages and the underlying Open XML schema elements within a package. The Open XML SDK 2.5 encapsulates many common tasks that developers perform on Open XML packages, so that you can perform complex operations with just a few lines of code.
It looks like it is not easy to solve your problem using the Open XML SDK. If you use Aspose.Slides for .NET you will copy a slide with its notes as shown below:
var sourceFileName = "example1.pptx";
var targetFileName = "example2.pptx";
var slideIndex = 0;
using (var sourcePresentation = new Presentation(sourceFileName))
using (var targetPresentation = new Presentation(targetFileName))
{
var slide = sourcePresentation.Slides[slideIndex];
targetPresentation.Slides.AddClone(slide);
targetPresentation.Save(targetFileName, SaveFormat.Pptx);
}
You can also evaluate Aspose.Slides Cloud for presentation manipulating. This REST-based API allows you to make 150 free API calls per month for API learning and presentation processing. The following code example shows you how to do the same using Aspose.Slides Cloud:
var slidesApi = new SlidesApi("my_client_id", "my_client_key");
var sourceFileName = "example1.pptx";
var targetFileName = "example2.pptx";
var slideIndex = 1;
using (var sourceStream = File.OpenRead(sourceFileName))
slidesApi.UploadFile(sourceFileName, sourceStream);
using (var targetStream = File.OpenRead(targetFileName))
slidesApi.UploadFile(targetFileName, targetStream);
slidesApi.CopySlide(targetFileName, slideIndex, null, sourceFileName);
using (var resultStream = slidesApi.DownloadFile(targetFileName))
using (var fileStream = File.OpenWrite(targetFileName))
resultStream.CopyTo(fileStream);
I work as a Support Developer at Aspose.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andrey Potapov |
