Main Content

Create and Format Images

Create an Image

To create an image to a report, create an mlreportgen.dom.Image object. You can append it to one of these document element objects:

  • Document

  • Group

  • Paragraph

  • ListItem

  • TableEntry

For example, you can create a MATLAB® figure, save it as an image, and add the image to a report.

import mlreportgen.dom.*
d = Document('imageArea','html');

p = Paragraph('Plot 1');
p.Bold = true;
append(d,p);

x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y);

saveas(gcf,'myPlot_img.png');

plot1 = Image('myPlot_img.png');
append(d,plot1);

close(d);
rptview(d.OutputPath);

For a list of supported image formats, see mlreportgen.dom.Image.

Resize an Image

To resize an image object, you can:

  • Set the Image.Height and Image.Width properties.

  • Use an mlreportgen.dom.Height or mlreportgen.dom.Width object in an Image.Style property definition.

For Microsoft® Word and PDF reports, you can use an mlreportgen.dom.ScaleToFit object to scale an image so that it fits within the page margins or in a table entry that contains it.

Image Storage

Keep the original file until it has been copied into the document. The DOM API copies the contents of the source image file into the output document when you close the document.

Links from an Image

You can specify an area in an image as a link. Clicking a link area in an image in an HTML browser opens the link. For details, see Create Image Maps.

See Also

| | |

Related Examples

More About