Create Links

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.

Create a Link Target

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,InternalLink('home','Go to Top'));


Create an External Link

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');



Create an Internal Link

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');


Add Text or Images to Links

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.

Create a Page Reference

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');

% 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.');

% 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');


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.

See Also

| | | |

Related Examples

More About