DominikPalo's avatar
DominikPalo
Iron Contributor
Oct 13, 2022
Status:
New

PowerPoint JS API: Add support for getting dimensions of slides

Currently, only the https://learn.microsoft.com/en-us/javascript/api/powerpoint/powerpoint.shape?view=powerpoint-js-preview class has the https://learn.microsoft.com/en-us/javascript/api/powerpoint/powerpoint.shape?view=powerpoint-js-preview#powerpoint-powerpoint-shape-width-member and https://learn.microsoft.com/en-us/javascript/api/powerpoint/powerpoint.shape?view=powerpoint-js-preview#powerpoint-powerpoint-shape-height-member properties. It would be really beneficial for us to have the same properties also for the https://learn.microsoft.com/en-us/javascript/api/powerpoint/powerpoint.slide?view=powerpoint-js-preview class.

 

Use case:

We need to insert content add-ins covering the entire slide. As content add-in allows us to specify only fixed dimensions in the manifest (https://learn.microsoft.com/en-us/javascript/api/manifest/requestedwidth?view=excel-js-preview and https://learn.microsoft.com/en-us/javascript/api/manifest/requestedheight?view=excel-js-preview), our idea is to automatically resize newly inserted content add-ins to the dimensions of the parent slide. e.g.:

 

contentAddinShape.left = 0;
contentAddinShape.top = 0;
contentAddinShape.width = parentSlide.width;
contentAddinShape.height = parentSlide.height;

 


Alternative solution:
Allow setting https://learn.microsoft.com/en-us/javascript/api/manifest/requestedwidth?view=excel-js-preview and https://learn.microsoft.com/en-us/javascript/api/manifest/requestedheight?view=excel-js-preview in relative units, so we could use something like:

 

<DefaultSettings>
  <RequestedWidth>100%</RequestedWidth>
  <RequestedHeight>100%</RequestedHeight>
</DefaultSettings>

 

3 Comments

  • Tjerkdb345's avatar
    Tjerkdb345
    Copper Contributor

    You can (with a workaround) get the dimensions of a slide. Here is a simple example:

     

    var slideImg = slide.getImageAsBase64();

    await slide.context.sync();

     

    //create an new image (that wont be loaded) based on the bas64 string and set the dimensions

    const img = new Image();

    img.src = "data:image/jpeg;base64, " + slideImg.value;

    await img.decode();

     

    return { width: img.width, height: img.height };

    • Pawlu's avatar
      Pawlu
      Brass Contributor

      We're also using `getImageAsBase64()` in order to get the slide width/height. However, we found it does have issues since you need to convert from pixels to points which is dependant on the user's DPI. Its nice to have but we really need MS to give us the dimensions.

  • macg's avatar
    macg
    Copper Contributor

    There are so many reasons why you'd want the height and width of a slide.  I cannot believe this is not part of the API already.