Aspose.Pdf

Hyperlinks to Pages in the Same PDF Document

These links refer to pages in the same document. It means that developers can create hyperlinks to any page in the same PDF document. For instance, One text Segment can be linked with another Text Paragraph . We know that we can assign a unique ID to any Paragraph (See: Assign ID to Paragraph ). So, we can simply use that ID to create a link between any Segment and a Text Paragraph .

 

Please follow the steps below to create such hyperlink:

 

 

Using the above steps, developers can create internal document links easily.

 

Example:

 

[C#]

 

//Create text paragraph with the reference of a section

Text text1 = new Text(sec1);

 

//Add the text paragraph in the paragraphs collection of the section

sec1.Paragraphs.Add(text1);

 

//Add a text segment in the text paragraph

segment1 = text1.Segments.Add("this is a local link");

 

//Set the text in the text segment to be underlined

segment1.TextInfo.IsUnderline = true;

 

//Set the link type of the text segment to Local

segment1.Hyperlink.LinkType = HyperlinkType.Local;

 

//Assign the id of the desired paragraph as a target id for the text segment

segment1.Hyperlink.TargetID = "product1";

 

//Create a text paragraph to be linked with the text segment

Text text3 = new Text(sec1,"product 1 info ...");

 

//Add the text paragraph to paragraphs collection of the section

sec1.Paragraphs.Add(text3);

 

//Set this paragraph to be the first so that it can be displayed in a separate

//page in the document

text3.IsFirstParagraph = true;

 

//Set the id of this text paragraph to "product1"

text3.ID = "product1";

 

[VB.NET]

 

'Create text paragraph with the reference of a section

Dim text1 As Text = New Text(sec1)

 

'Add the text paragraph in the paragraphs collection of the section

sec1.Paragraphs.Add(text1)

 

'Add a text segment in the text paragraph

segment1 = text1.Segments.Add("this is a local link")

 

'Set the text in the text segment to be underlined

segment1.TextInfo.IsUnderline = True

 

'Set the link type of the text segment to Local

segment1.Hyperlink.LinkType = HyperlinkType.Local

 

'Assign the id of the desired paragraph as a target id for the text segment

segment1.Hyperlink.TargetID = "product1"

 

'Create a text paragraph to be linked with the text segment       

Dim text3 As Text = New Text(sec1, "product 1 info ...")

 

'Add the text paragraph to paragraphs collection of the section

sec1.Paragraphs.Add(text3)

 

'Set this paragraph to be the first so that it can be displayed in a separate

'page in the document

text3.IsFirstParagraph = True

 

'Set the id of this text paragraph to "product1"

text3.ID = "product1"

 

[XML]

 

<Text>

     <Segment TargetID="product1" LinkType="Local" IsUnderline="true">

        this is a local link

     </Segment>

</Text>

<Text IsFirstParagraph="true" ID="product1">

     <Segment> product 1 info ...</Segment>

</Text>