An external document link refers to a page in another PDF document. Aspose.Pdf allows to create hyperlinks to pages in other PDF documents.
Please follow the steps below to create an external hyperlink:
Using the above steps, developers can create external document links easily.
Code Snippet
[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 pdf link");
//Set the text in the segment to be underlined
segment1.TextInfo.IsUnderline = true;
//Set the link type of the text segment to Pdf
segment1.Hyperlink.LinkType = HyperlinkType.Pdf;
//Set the path of the external document
segment1.Hyperlink.LinkFile = "C:/result.pdf";
//Set the page number of the document to which the link is to be created
segment1.Hyperlink.LinkPageNumber = 2;
[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 pdf link")
'Set the text in the segment to be underlined
segment1.TextInfo.IsUnderline = true
'Set the link type of the text segment to Pdf
segment1.Hyperlink.LinkType = HyperlinkType.Pdf
'Set the path of the external document
segment1.Hyperlink.LinkFile = "C:/result.pdf"
'Set the page number of the document to which the link is to be created
segment1.Hyperlink.LinkPageNumber = 2
[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 pdf link");
//Set the text in the segment to be underlined
segment1.getTextInfo().setUnderLine(true);
//Set the link type of the text segment to Pdf
//Set the page number of the document to which the link is to be created
segment1.setHyperLink(new HyperLinkToOuterPdf("c:/result.pdf",2));
[XML]
<Text>
<Segment LinkType="Pdf" IsUnderline="true" LinkFile="C:/result.pdf"
LinkPageNumber="2">
this is a pdf link
</Segment>
</Text>