Main Content

mlreportgen.dom.Image Class

Namespace: mlreportgen.dom

Image to include in report

Description

Use an object of the mlreportgen.dom.Image class to include an image in a report.

The mlreportgen.dom.Image class is a handle class.

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

imageObj = mlreportgen.dom.Image(imagePath) creates an mlreportgen.dom.Image object with the Path property set to the path of an image.

Note

The contents of the specified image file are copied into the output document when the document is closed. Do not delete or overwrite the image file before closing the document. If you create an image file and the corresponding mlreportgen.dom.Image object in a loop, for each loop iteration, use a unique file name for the image file.

example

Input Arguments

expand all

Path of an image file to include in a report, specified as a character vector or string scalar. You can use these image formats.

Import Image FormatSupported in HTMLSupported in WordSupported in PDF

Supported in PDF/A (since R2025a)

Windows® metafile (.emf)NoYesNoNo
Graphics Interchange Format (.gif)YesYesYesYes
JPEG image (.jpg)YesYesYesNo
PDF (.pdf)NoNoYesNo
PDF/A (.pdf)NoNoYesNo
Portable Network Graphics (.png)YesYesYesYes
Scalable Vector Graphics (.svg)YesYesYesYes
TIFF image (.tif)NoYesYesYes

Note

Unlike the PDF report output format, the PDF/A format does not support including PDF or PDF/A images. Use one of the image formats listed in the table to include an image in a PDF/A report.

Properties

expand all

Path of image file, specified as a character vector or string scalar.

Attributes:

GetAccess
public
SetAccess
private
NonCopyable
true
Transient
true

Data Types: char | string

Image height, specified as a character vector or string scalar that contains a number followed by an abbreviation for a unit of measurement. For example, "2in" specifies two inches. Valid abbreviations are:

  • px — Pixels

  • cm — Centimeters

  • in — Inches

  • mm — Millimeters

  • pc — Picas

  • pt — Points

  • % — Percent

When you create the mlreportgen.dom.Image object , this property is initially set to a value based on the image file specified by the Path property.

If you set the Style property of a mlreportgen.dom.Image object, the style height overrides this property value.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Image width, specified as a character vector or string scalar that contains a number followed by an abbreviation for a unit of measurement. For example, "2in" specifies two inches. Valid abbreviations are:

  • px — Pixels

  • cm — Centimeters

  • in — Inches

  • mm — Millimeters

  • pc — Picas

  • pt — Points

  • % — Percent

When you create the mlreportgen.dom.Image object , this property is initially set to a value based on the image file specified by the Path property.

If you set the Style property of a mlreportgen.dom.Image object, the style width overrides this property value.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Map of hyperlink areas in this image, specified as an mlreportgen.dom.ImageMap object. The Map property applies to only HTML and PDF reports.

See Create Image Maps.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Whether to embed an SVG file, specified as true or false. When this property is false, the report renders SVG images using CSS. When this property is set to false, you cannot search for images. If true, the generated HTML report file includes the generated HTML report file includes a copy of the SVG file. When this property is true, you can search for images, but SVG images that rely on CSS formatting may render incorrectly.

Note

The EmbedSVG property applies only to HTML reports.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Name of stylesheet-defined style, specified as a character vector or string scalar. The style name is the name of a style specified in the style sheet of the document or document part to which this element is appended. The specified style defines the appearance of this element in the output document unless the formats specified by the Style property of this element override it. To learn more about using style sheets, see Use Style Sheet Styles.

Note

Microsoft® Word reports ignore style names that are not defined in the document template. For more information on Microsoft Word templates, seeTemplates for DOM API Report Programs.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Format specification for this document element object, specified as an array of DOM format objects. The formats specified by this property override corresponding formats specified by the StyleName property of this element. Formats that do not apply to this document element object are ignored.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Custom attributes of the document element, specified as an array of mlreportgen.dom.CustomAttribute objects. The custom attributes must be supported by the output format of the document element to which this object is appended.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Parent of this object, specified as a document element object. A document element must have only one parent.

Attributes:

GetAccess
public
SetAccess
private
NonCopyable
true

The class ignores this property.

Attributes:

GetAccess
public
SetAccess
private
NonCopyable
true

Tag, specified as a character vector or string scalar. The DOM API generates a session-unique tag as part of the creation of this object. The generated tag has the form CLASS:ID, where CLASS is the object class and ID is the value of the Id property of the object. Use this value to help identify where an issue occurs during document generation.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Object identifier, specified as a character vector or string scalar. The DOM API generates a session-unique identifier when it creates the document element object.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Methods

expand all

Examples

collapse all

Use an mlreportgen.dom.Image object to specify an image that you want to include in a report. Include the image in the report by appending the Image object to the report.

Import the DOM namespace so that you do not have to use long, fully qualified class names.

import mlreportgen.dom.*

Create a report and add a title for the image using an mlreportgen.dom.Paragraph object.

d = Document("myImageReport","docx");

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

Save a plot as an image file.

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

saveas(gcf,"myPlot_img.png");

Figure contains an axes object. The axes object contains an object of type line.

Create an mlreportgen.dom.Image object that specifies the path of the image file. Specify that the width and height are 4 inches. Append the Image object to the report.

plot1 = Image("myPlot_img.png");
plot1.Width = "4in";
plot1.Height = "4in";
append(d,plot1);

Close and view the report.

close(d);
rptview(d);

Here is the image in the generated report:

Version History

Introduced in R2014b

expand all