You can add these kinds of links to a report:
External — Link to a location outside of the report, such as an HTML
page or a PDF file. Use an mlreportgen.dom.ExternalLink
object.
Internal — Link to locations in the report. Use an
mlreportgen.dom.InternalLink
object.
To specify the link target for an InternalLink
object, use the
value in the Name
property of an
mlreportgen.dom.LinkTarget
object. When you construct an
ExternalLink
object, you can use a
LinkTarget
object Name
value or a
URL.
This example creates a link target called home
, and uses
home
as the target for an internal link.
import mlreportgen.dom.* d = Document('mydoc'); append(d,LinkTarget('home')); append(d,InternalLink('home','Go to Top')); close(d); rptview(d.OutputPath);
Use an mlreportgen.dom.ExternalLink
object to create an external
link, specifying the link target and the link text.
import mlreportgen.dom.* d = Document('mydoc'); append(d,ExternalLink('https://www.mathworks.com/','MathWorks')); close(d); rptview('mydoc','html');
To set up links to a location in a report, append an
mlreportgen.dom.InternalLink
object to the document or document
element. Use an mlreportgen.dom.LinkTarget
object with the document
element to link to. For example, you can include an About the
Author
link to a section that has the heading Author's
Biography
.
import mlreportgen.dom.* d = Document('mydoc'); append(d,InternalLink('bio','About the Author')); h = Heading(1,LinkTarget('bio')); append(h,'Author''s Biography'); append(d,h); close(d); rptview('mydoc','html');
To add text or an image to an ExternalLink
or
InternalLink
object, use the
append
method with that object. Append a Text
, Image
, or
CustomElement
object.
You can create a numeric reference to the page where a link target resides. For example, you can create a page reference in the form “See page 15,” where the target you are referencing is on an object on page 15. For example:
import mlreportgen.dom.*; d = Document('mydoc','pdf'); open(d); % Add target to heading object and append heading and % para text to document h = Heading1(LinkTarget('mytarget')); append(h,'Referenced Head'); p = Paragraph('Here is some paragraph text.'); append(d,h); append(d,p); % Add another page and insert the page reference % to the target p1 = Paragraph('The following paragraph contains the page reference.'); p1.Style = {PageBreakBefore(true)}; p2 = Paragraph('See Page '); p2.WhiteSpace = 'preserve'; ref = PageRef('mytarget'); append(p2,ref); append(p2,'.'); append(d,p1); append(d,p2); close(d); rptview(d.OutputPath);
In your PDF template, you can use a <pageref>
element to
create this kind of reference. Your DOM API program must set the link target that
the element uses. The <pageref>
uses one argument:
<pageref target="nameoftarget>
.
For more information on this mechanism, see mlreportgen.dom.PageRef
.
append
| mlreportgen.dom.ExternalLink
| mlreportgen.dom.InternalLink
| mlreportgen.dom.LinkTarget
| mlreportgen.dom.PageRef