openxml convert/copy PresentationDocument read from disk to a memory stream

50 views Asked by At

In VS C#, I'm trying to replace Spire (a third party .pptx creator) with OpenXML. (Spire is probably a simplifictation written on top of PresentationML, something like CloseXML is for Excel.)

There are a relatively small number of functions and lines of code to be replaced. In the current code using Spire, I can create a "presentation" in memory, add slides to it, add shapes to the slides, and then save the presentation to a file, which I specify as a memory stream. I can then zip and export the memory stream. Works slick.

To replace Spire I started working with OpenXML replacing the Spire functions one at a time. I'm using the Open XML SDK tool, and comfortable with it.

Using only OpenXML, I am able to create a PresentationDocument in a memory stream. And I'm able to build slides and add shapes to them. However, in trying to add the slides to the presentation, I encountered some confusion in needing to add lots of OpenXML "parts" to the PresentationDocument in order to add the slides in the right location.

I figured I could copy a lot of the SDK reflected code to build all those parts, however...

I thought instead maybe I could create a "real" PPTX, put it in my AppData folder, open from disk, and modify it. So I would not have to assemble the full PPTX in OpenXML.

I was able to locate and open the PPTX from disk:

 PresentationDocument presentationDoc1 = PresentationDocument.Open(path1, false);

However at this point I cannot figure out how to copy, save, clone or convert that into a MemoryStream such as this:

var wrkFileStream = new MemoryStream();
PresentationDocument presentationDoc2 = PresentationDocument.Create(wrkFileStream, 0); 

If I could do that, I would have a pre-built PresentationDocument that I could then connect to the existing code for slides and slide shapes.

So the question is, how might I copy, save, clone or convert PresentationDocument read from disk into a PresentationDocument in a memory stream?

0

There are 0 answers