How can I center an image horizontally and vertically in a PDF created with Report Generator?
7 views (last 30 days)
Show older comments
MathWorks Support Team
on 7 Feb 2019
Answered: MathWorks Support Team
on 7 Feb 2019
How can I center an image horizontally and vertically in a PDF created with Report Generator?
Accepted Answer
MathWorks Support Team
on 25 Apr 2019
To center an image in a report programmatically , you can modify the "Style" property of the image. The "Style" property of an image and other DOM document objects is a cell array of format objects, which you can use to style the DOM document object. Here is an example of how you can add a "HAlign" object to "Style" property of the "thePlot" image to center it in the PDF:
plotPath = getSnapshotImage(fig, R);
halign = mlreportgen.dom.HAlign('center');
thePlot.Style = [thePlot.Style(:)' {halign}];
However, adding a "VAlign" format object to the "Style" property of the image will not vertically align the image to the center of the page. PDF viewers honor the "VAlign" property only for DOM objects that are children of objects that have a specifiable height. Although pages have a specifiable height, they are not DOM objects so adding a "VAlign" object to the style property of an image that is a child of a page will not center the image. However, you can vertically align an image using the "VAlign" format object on a page if the image is a child of a 1 by 3 invisible table whose width and height are equivalent to the page body's width and height. To see an example, open the script "alignImage.m" attached and look at the "centerImage" function in the script for details..
0 Comments
More Answers (0)
See Also
Categories
Find more on Image Analysis 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!