Main Content

Create Report Programs

The MATLAB® Report Generator™ includes classes that allow you to create report generator programs. These programs can generate Microsoft® Word, HTML, and PDF reports. The programs must include certain items and can include some optional items, both of which are listed here and described at each associated link. For information on Report API and how it compares to the Document Object Model (DOM), see What Are Reporters?

Required Report Program Tasks and Elements

All report generator programs must:

Optional Report Program Tasks and Elements

Optionally, in report generator programs, you:

  • Import Report API classes, which enables using non-fully qualified Report API class names, for example, TitlePage, instead of mlreportgen.report.TitlePage. See Import API namespaces.

  • Import DOM API classes, if the program adds DOM objects to the report, which enables using non-fully qualified DOM API class names.

  • Configure reporters by setting their property values. See Content Generation.

  • Add content to reporters by using the add method.

    Note

    The only reporters you can both configure and add content to are the Section and Chapter reporters. The Chapter reporter is a subclass of the Section reporter.

  • Display the report to see the generated report output. See Display Reports.

  • Display report progress messages to monitor report progress. See Display Progress and Debugger Messages.

Generate and Display a PDF Report Programmatically

This example shows how to generate and display a PDF report using the Report API.

1. Import report API classes.

import mlreportgen.report.*

2. Add a report container.

rpt = Report("output","pdf");

3. Add title page and table of contents reporters to the container.

titlepg = TitlePage;
titlepg.Title = "My Airplane";
titlepg.Author = "Pilot A";
add(rpt,titlepg);
add(rpt,TableOfContents);

4. Add a chapter that contains text and images to the report.

chap = Chapter("Plane Image");
add(chap,"Here is the plane:");
add(chap,FormalImage("Image","b747.jpg", ...
    "Height","5in","Width","5in", ...
    "Caption","Boeing 747"));
add(rpt,chap);

5. Close the report.

close(rpt);

6. Display the report.

rptview(rpt);

Report title page with the title "My Airplane", the author "Pilot A", and the date.

Table of contents listing one image.

Presentation page 1 with text that says, "Chapter 1. Plane Image. Here is the plane:" and an image of a Boeing 747.

See Also

Topics