Main Content

Create and Format Images

Create Images

To add 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 Images

To resize an image object, you can:

  • Set the Height or Width properties of the image. If you set only one dimension, the object does not resize the unset dimension.

  • Set the Style property of the image by using mlreportgen.dom.Height or mlreportgen.dom.Width objects. If you set only one dimension, the object resizes the unset dimension in order to preserve the aspect ratio.

For Microsoft® Word and PDF reports, you can use an mlreportgen.dom.ScaleToFit object to scale an image to fit within the page margins or in the 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 Images

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

| | |

Topics