Search code examples
ms-wordoffice-jsopenxmloffice-addins

Office.js: Change page size


How do we change the page size of a section in Office.js? There is no option in the API (latest version). I have tried doing it through OOXML using several different schemes, to no avail.

I have confirmed (by editing a Docx file manually) that you need to change w:w and w:h attributes of w:pgSz node to change the page size. However, when inserting OOXML, I really can't figure out which object I need to insert it. For example I have tried context.document.body.insertOoxml() as well as context.document.sections.getFirst().body.insertOoxml(), both of which do not change page size in any way.

I have also tried using Section.set() function without success.

Can anyone share how to achieve this?

Edit

The root of the problem seems to be that page size is stored in sectPr node, which Office.js never load. I have tried load() function as well as context.loadRecursive(). I can load Sections collection and their scalar and navigation properties just fine, but properties of the section are never loaded. I'm not sure what else I can do.

The other method, that of inserting raw OOXML, also fails because insertOoxml() method is not available with the Section object, but only with Section.body, which affects the contents of the section and not its meta properties.


Solution

  • MS guys from Office.js team have told me that this is currently not possible with JS-based add-ins. What a pity. After 10 years of development, Office.js was supposed to be more powerful than this.

    And yes, I have tried both the API as well as OOXML. None of them appears to work.