Why does the "replace" function for "PicturePlaceholder" not maintain a picture's aspect ratio in MATLAB R2022b?
14 views (last 30 days)
Show older comments
MathWorks Support Team
on 19 Oct 2022
Answered: MathWorks Support Team
on 30 Jan 2023
I am generating PowerPoint slides programmatically using the MATLAB Report Generator. In MATLAB R2019b, when I replace a picture placeholder in a slide with an image that's smaller than the placeholder, the image is stretched proportionally while maintaining its aspect ratio. However, in MATLAB R2022b, the image is stretched to fill the entire picture placeholder, and the image's original aspect ratio is not maintained.
How can I resolve this issue? The following example code and screenshots demonstrate the issue:
% Create Slides
pre = Presentation('TestPPTout.pptx','TestTemplate1.pptx');
slide = add(pre, 'customLayout');
% Create mlreportgen.ppt.Picture from image
custImg = Picture(img);
% Replace the Place Holder with the image
placeHolderObj = find(slide,'customPlot');
replace(placeHolderObj,custImg);
Accepted Answer
MathWorks Support Team
on 19 Oct 2022
In PowerPoint, the intended behavior of a Picture Placeholder is that when an image is added to it, the image should completely fill the placeholder area, overriding the aspect ratio if needed.
The old behavior in MATLAB R2019b, where the picture maintains its aspect ratio after replacing the "PicturePlaceholder", is unintended. It was fixed in MATLAB R2021a.
To maintain the picture's aspect ratio, use a "ContentPlaceholder" instead. To do this, edit the PowerPoint template and replace the picture placeholders with content placeholders. In the MATLAB script, call "replace" on the "ContentPlaceholder" object the same way as for a "PicturePlaceholder". Please refer to the following documentation for more information on the "ContentPlaceholder" class:
0 Comments
More Answers (0)
See Also
Categories
Find more on MATLAB Report Generator in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!