1

I developing a custom addin for Microsoft PowerPoint. My addin needs to store large amount of binary data into PowerPoint presentation. I store this binary data as base 64 encoded strings into PowerPoint presentation tags. I found, that when presentation contains huge amount of data in its tags (like 10+ megabytes), PowerPoint seems to be leaking memory when saving the presentation. So when such presentation is saved multiple times, PowerPoint even my run out of system memory and crash.

I developed a very simple C# addin to isolate the issue. It stores 50 megabytes of binary data into presentation when new presentation is created:

private void Application_AfterNewPresentation(PowerPoint.Presentation presentation)
{
    int tagLength = 5 * 1000 * 1000;
    StringBuilder largeTagValue = new StringBuilder();
    largeTagValue.Capacity = tagLength + 2;
    for (int i = 0; i < tagLength; i++)
    {
        largeTagValue.Append("A");
    }
    largeTagValue.Append("\0");
    string largeTagValueString = largeTagValue.ToString();
    for (int i = 0; i < 10; i++)
    {
        presentation.Tags.Add("LARGE_TAG" + i.ToString(), largeTagValueString);
    }
}

After running this addin, I may even disable it to make sure that it not does anything more. Next, I am saving the presentation multiple times and see that PowerPoint memory usage in process list grows each time I save the presentation.

The complete source code and sample presentation is available here

Does anyone know if it is a PowerPoint bug or is there any workaround for this?...

Or, maybe there is another way to store relatively large amount of data into PowerPoint presentation?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • I'd assume it's a bug; surely it's not *designed* to leak memory, crash and burn. I don't have the information handy, but I'm fairly sure I saw, somewhere, an explanation of how you could include any arbitrary file within a PowerPoint file, assuming you're using one of the XML formats (PPTX, PPTM, PPSX etc.). – Steve Rindsberg Mar 23 '13 at 16:57
  • Steve, do you have any ideas how to store a binary file in PPTX without using PowerPoint tags? – Roman Petrov Mar 27 '13 at 08:23

1 Answers1

0

A bit more searching turned this up ... have a look at Todd Main's answer first to get a general idea of what's needed:

Is it possible to add some data to a Word document?

Community
  • 1
  • 1
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
  • Steve, thank you for helpful response. I think, I can try to store binary data in custom XML part of PowerPoint presentation. However, this approach still might some drawbacks. 1. I will still have to encode my binary data to base 64 and this will increases presentation file size. 2. I wonder if PowerPoint presentation loader will work correctly if I put a huge XML file into the presentation (like ~50 megabytes). I need an ability to store multiple files into the presentation. So I will try this approach to see if it works for me. Thanks again. – Roman Petrov Mar 28 '13 at 09:37
  • You can do some tests as to load time w/o having to write all the code; insert OLE objects (Excel objects, Word objects, Photoshop objects, whatever) into a presentation and save it, then crack open the PPTX(ZIP) file and look at how the OLE objects have been stored and how they affect load time etc. – Steve Rindsberg Mar 28 '13 at 14:30
  • Thank you Steve. It's an interesting idea, I will try this. – Roman Petrov Mar 29 '13 at 09:01