Postprocessing of M2Doc Documents by Visual Basic


descriptions of Capella model elements may contain images. If such descriptions are included in a M2Doc template using M2DocHTMLServices the images do not scale to the page width. They stick out of the page and their size remains unchanged even if the original images in the description are resized. May be this can be changed by improving M2DocHTMLServices?

Another approach to solve this is to use a Visual Basic macro to resize all images in the document to fit the page width. Such kidn of postprocessing may be usable and more feasible also in other situations, that would otherwise be very hard to solve using (today´s) m2doc. Has anybody used this approach already?

Interesting to know would be if and how the people invoked the macro(s). Ideally, they would be invoked automatically just after the actual generation finishes. In manual mode but also if CLI is used to generate the document.


This is a limitation of the M2DocHTMLServices. The pixel size of the HTML image need conversion to the MS Word unit but I’m not sure what unit it should be. There is a TODO in M2DocHTMLServices.

You can also write a Java service that call the fit() service if the MElement is a MImage.

edit: after reading the code no conversion is needed here, all values are in pixels. I will fix that.

The fit() ImageService uses pixels, so I am not sure why you need a conversion to a unit. Could the image be resized to the page width when inserting it? A default page width could be computed using the most common screen DPI (90 or so), screen resolution (may be 1920x1080) and A4 page size. Or a variant of fromHtmlBodyString could be added with an additional parameter – width and height of images in pixels as in fit() ImageService.

You are right, the conversion happens later when inserting the MImage. I’ll fix this so the defined size in the HTML will be applied in the output document.

I made a patch.
The patched version is available using the nightly update site.

Thanks Yvan for the very quick remedy, indeed, we´ll test it. There is still a risk that this approach will not suffice, because if we set a page fitting width (e.g. 500) in the fit()in the template and we use the same value in the Capella description (properties of the image), in the latter our image is too small to be legible.

Copyright © Eclipse Capella, the Eclipse Capella logo, Eclipse and the Eclipse logo are Trademarks of The Eclipse Foundation.