Customize Simulink Diagram Hyperlinks in HTML and PDF Reports
R2026bThis example shows how to customize navigation hyperlinks of Simulink® diagrams embedded in PDF and HTML reports. By default, clicking on a diagram element navigates to the section of the report that documents that element. To specify a different destination for the hyperlinks, follow the procedure in this example.
Set up the report and load a Simulink model
Import the DOM and Report API packages so you do not have to use fully-qualified class names.
import mlreportgen.dom.* import slreportgen.report.*
Load a Simulink model.
model = "sf_car";
openExample(model);Create and open a Simulink report.
rpt = Report("myreport","pdf"); open(rpt);
Include the sf_car root system diagram using the Diagram reporter
The Diagram reporter overlays each element of the sf_car diagram
snapshot with a hyperlink to navigate to a section of the report that describes that
element. The hyperlink and its ID are created using the element's path in the model. For
example, a subsystem block, such as Engine or
transmission, includes a hyperlink used for navigating to the
corresponding subsystem diagram snapshot in the report.
diag1 = Diagram(model);
diag1.Snapshot.Caption = strcat("Diagram snapshot for root system: ",model);
add(rpt,diag1);
add(rpt,PageBreak);Include the sf_car/Engine subsystem diagram using the
Diagram reporter
This reporter prefaces the report object that it creates with a hyperlink target whose ID
is also based on the reported element's path in the model.The Diagram
reporter (diag1) for root system sf_car also uses the same ID to create
the hyperlink on the Engine block in the snapshot. So, clicking on the
Engine block automatically targets to this subsystem diagram snapshot in
the report.
engine = strcat(model,"/","Engine"); diag2 = Diagram(engine); diag2.Snapshot.Caption = strcat("Diagram snapshot for subsystem: ",engine); add(rpt,diag2); add(rpt,PageBreak);
Include the sf_car/transmission subsystem diagram using the
Diagram reporter
Clicking on transmission block in the sf_car root system diagram
snapshot navigates to the transmission subsystem diagram snapshot in the
report.
To customize the target for the hyperlink, remove the link target for this reporter by
setting the LinkTarget property of the reporter to an empty string. This
ensures that clicking on the transmission block in the sf_car root system
diagram snapshot does not navigate to the transmission subsystem diagram.
Then create a custom target for the hyperlink as described in the next section.
transmission = strcat(model,"/","transmission"); diag3 = Diagram(transmission); diag3.LinkTarget = ""; diag3.Snapshot.Caption = strcat("Diagram snapshot for subsystem: ",transmission); add(rpt,diag3); add(rpt,PageBreak);
Create custom target for the sf_car/transmission block
hyperlink
To set a new target for the hyperlink, first use the
slreportgen.utils.getObjectID function to obtain the same ID that the
Diagram reporter uses. Use the
SimulinkObjectProperties reporter to generate a property table for the
transmission block. Change the LinkTarget property of
the reporter to the ID obtained with slreportgen.utils.getObjectID. The
Diagram reporter (diag1) for root system sf_car also uses the same ID to
create the hyperlink on the transmission block in the snapshot, so
clicking on the block now targets this block property table.
id = slreportgen.utils.getObjectID(transmission); props = SimulinkObjectProperties(transmission); props.LinkTarget = id; add(rpt,props);
Close and view the report
close(rpt); rptview(rpt);