Aspose.Pdf

Hyperlink to a Web Location

A web link points to a web location. Aspose.Pdf also allows developers to create hyperlinks to a web location.

 

Please follow the steps below to create a hyperlink to a web location:

 

 

Code Snippet

 

[C#]

 

//Create text paragraph with the reference of a section

Text text2 = new Text(sec1);

 

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

sec1.Paragraphs.Add(text2);

 

//Add a text segment in the text paragraph

Segment segment2 = text2.Segments.Add("this is a web link");

 

//Assign a new instance of hyperlink to hyperlink property of segment

segment2.Hyperlink = new Hyperlink();         

 

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

segment2.Hyperlink.LinkType = HyperlinkType.Web;

 

//Set the URL of the web location to create a web link for the segment

segment2.Hyperlink.Url = "http://localhost/popup.htm";

 

[VB.NET]

 

'Create text paragraph with the reference of a section

Dim text2 As Text = New Text(sec1)

 

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

sec1.Paragraphs.Add(text2)

 

'Add a text segment in the text paragraph

Dim segment2 As Segment = text2.Segments.Add("this is a web link")

 

'Assign a new instance of hyperlink to hyperlink property of segment

segment2.Hyperlink = New Hyperlink()         

 

'Set the link type of the text segment to Web

segment2.Hyperlink.LinkType = HyperlinkType.Web

 

'Set the URL of the web location to create a web link for the segment

segment2.Hyperlink.Url = http://localhost/popup.htm

 

[JAVA]

 

//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.getParagraphs().add(text1);        

 

//Add a text segment in the text paragraph

Segment segment1 = text1.getSegments().add("this is a web link");                      

 

//Set the text in the segment to be underlined

segment1.getTextInfo().setUnderLine(true);                      

 

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

segment1.setHyperLink(new HyperLinkToWeb("http://localhost/popup.htm"));

 

 

[XML]

 

<Text>

     <Segment Url="http://localhost/Images/SeaFood.jpg" LinkType="Web">

        this is a web link

     </Segment>

</Text>