How to adjust picture properties embedded into Powerpoint?
조회 수: 15 (최근 30일)
이전 댓글 표시
I have no experience with generating Powerpoint output with Matlab and have looked up the very minimal basics to get me going. I find that what I embed into a .pptx isn't giving me the desired output - to begin with, the size/aspect ratio. Here is an example:
import mlreportgen.ppt.*
splot = Picture('ABC.png');
splot.Width = '800px'; splot.Height = '480px';
pictureSlide = add(ppt, 'Title and Picture');
replace(pictureSlide, 'Picture', splot);
close(ppt);
This does not produce the desired aspect ratio in the .pptx. The original png was saved as 800x480. Alternatively, using .Width = '5in' & .Height = '3in' doesn't change things either. The embedded picture is very wide-format and seems to be a best-fit for the slide area, maybe conforming to what a picture placeholder would be. There is no other Powerpoint related code in the script and no templates or anything being loaded or created.
In short, is there a way to simply embed the picture while preserving the original aspect ratio of the png image?
댓글 수: 1
Jessica Johnson
2022년 12월 11일
Were you ever able to resolve this? I find myself with the exact same problem. Thanks
답변 (1개)
Sumukh
2024년 9월 20일
Hi AR,
I have reproduced the issue you are facing, and it is indeed true that the aspect ratio cannot be maintained using the “PicturePlaceholder” object.
A possible solution is to use the “ContentPlaceholder” object instead of the “PicturePlaceholder” object. You can run the following command in the command window to know more about content placeholders:
web(fullfile(docroot, 'rptgen/ug/mlreportgen.ppt.contentplaceholder-class.html'))
The image can be placed in the “Content” section of the slide using this object. The aspect ratio and dimensions of the image are maintained in the slide if no dimensions are passed to the Picture object “splot” in the code provided. If the dimensions are changed while maintaining the aspect ratio, the image in the slide accordingly maintains the aspect ratio within the “ContentPlaceholder” object.
You can refer to the following code to understand how content placeholder can be used to maintain aspect ratio of images in PowerPoint slides:
% Import the PPT namespace:
import mlreportgen.ppt.*
% Create a Presentation object :
ppt=Presentation('ImagePPT.pptx');
% Open the object:
open(ppt);
% Create a Picture object using .png image:
splot = Picture('glass.png');
% Change dimensions, if necessary, while maintaining aspect ratio
% splot.Width ='';
% splot.Height ='';
% Create a "Title and Content" type slide
pictureSlide = add(ppt, 'Title and Content');
% Replace the "Content" with the image
replace(pictureSlide, 'Content', splot);
% Close the ppt object
close(ppt);
Once run, the file “ImagePPT.pptx” contains a slide with the .PNG image. The image will have default dimensions with its aspect ratio intact and not stretched across the slide. I have attached the image file being used with this answer.
I hope this resolves your issue.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!