joelby
joelby

Reputation: 87

MS PowerPoint JavaScript API - insert SVG as shape?

I'm using the Office.context.document.setSelectedDataAsync() method and Office.CoercionType.XmlSvg to insert complex objects into slides, which works quite well!

The only caveat seems to be that you need to right click and "Convert to Shape" before they can be edited inside PowerPoint. Is there some way to insert SVG objects as a Shape or to effectively automate the "Convert to Shape" step using the JavaScript API?

Upvotes: 1

Views: 1094

Answers (1)

Onur Onder
Onur Onder

Reputation: 346

I see, thanks for the additional explanation, unfortunately currently PowerPoint OfficeJS Api is very thin, although it is being actively worked on, there is currently no other API to do the "Convert to Shape" or insert a shape yet.

I don't know your requirements, however, may I recommend you a newly released API which allows you to insert a slide from a PPTX file? Instead of converting to SVG, you can possibly insert directly. This is currently available in Public Preview which you can find information here: https://learn.microsoft.com/en-us/javascript/api/powerpoint/powerpoint.presentation?view=powerpoint-js-preview#insertSlidesFromBase64_base64File__options_

Preview API list can be found here: https://learn.microsoft.com/en-us/office/dev/add-ins/reference/requirement-sets/powerpoint-preview-apis

Here are some sample code to insert slides from existing files:

    await PowerPoint.run(async function(context) {
      context.presentation.insertSlidesFromBase64( base64EncodedPptxFileAsString );
      context.sync();
    });

    await PowerPoint.run(async function (context) {
      context.presentation.insertSlidesFromBase64( base64EncodedPptxFileAsString,
        {
          formatting: "UseDestinationTheme",
          targetSlideId: "257#",
          sourceSlideIds: ["257#3396654126", "258#"]
        });
      context.sync();
    });

Upvotes: 1

Related Questions