How to scale images in docx documents using ONLYOFFICE macros

October 12, 2024
Author: Mona

Recently, we created a macro for scaling images in the presentation editor . Next, we will expand on this functionality and create a macro that makes it easier to modify images in documents, including resizing, cropping, and more. Let’s take a look at how to build this simple macro.

We first define the processImage() function, which is responsible for processing the modification of images in the document and iterating over each image in the document through the forEach() method.

In the forEach loop, call

SetSize() method to adjust the switzerland whatsapp number data size of each picture to the required width and height. The default value is 100 x 100 mm. Of course, you can also adjust these parameters according to your needs.

Note: The SetSize() method uses EMUs ( imperial units ) as the size unit . Therefore , you need to multiply the width and height provided (in millimeters) by 36,000 to convert to EMUs . If you do not convert, passing in millimeters directly will have no effect .

Next comes the main part of the macro

We first get the document in the document variable and store all the images in the document into the allImg array.

Next, we perform an if statement to ensure that the allImg array exists and is not empty. If any of the conditions are not met, the execution of the macro will be terminated.

Complete macro code

Here is the complete macro code

At this point, we have finished creating a macro! This simple macro will help you adjust images in your document with one click. ONLYOFFICE API is a powerful tool that can handle a wide range of tasks and provides afb directory endless possibilities for developing more macros and plugins. Using this API, you can take advantage of all ONLYOFFICE features, increase your productivity, and simplify your workflow.

If you have any questions or innovative buy phone number data ideas, please share them with us . We value your feedback and look forward to working with you. Good luck exploring!

 

 

Scroll to Top