Convert a restricted selection of external links to internal links.




int LinkDestinations(IEnumerable<int> ids)
int LinkDestinations(IEnumerable<int> linkIDs, IEnumerable<int> destIDs, bool linkPages)

[Visual Basic]
Sub LinkDestinations(ids As IEnumerable(Of Integer))
Sub LinkDestinations(linkIDs As IEnumerable(Of Integer), destIDs As IEnumerable(Of Integer), linkPages As Boolean)



Name Description
ids Specifies both linkIDs and destIDs.
linkIDs The list of IDs of view objects containing links (anchor tags with href attributes).
destIDs The list of IDs of view objects containing destinations (anchor tags with name attributes).
linkPages Whether links pointing to the URLs of HTML pages (URLs without fragments) are converted to internal links. The default value is false.
return The number of links converted.




This method scans the view objects specified in linkIDs converting external links to internal links where the destinations are found in the view objects specified in destIDs. It is similar to the LinkPages method but allows you to restrict the conversion to lists of view objects.

By default, links in rendered HTML are preserved as is. This means that links in a web page link to external URLs. When you click on them, a browser window will be launched and the original target of the link displayed.

In some situations, you may wish to resolve links within the document so that they take you between pages in the PDF rather than launching an external browser window.

For example, you might add a number of web pages which contain links to each other. Rather than linking to the pages on the original web site, you might like to resolve the links so that they point at the pages as they now appear in the PDF.

Similarly, if you use named destinations (HTML fragments) with links within the document, you will may wish to use this method to convert them from external links to internal ones.




This example shows how to import an HTML page which uses named destinations.

We first create a Doc object and inset the edges a little so that the HTML will appear in the middle of the page. We assign the appropriate HTML options so that links will be rendered live.

Doc theDoc = new Doc();
theDoc.Rect.Inset(18, 18);
theDoc.HtmlOptions.AddLinks = true;

[Visual Basic]
Dim theDoc As Doc = New Doc()
theDoc.Rect.Inset(18, 18)
theDoc.HtmlOptions.AddLinks = True

We add the pages to the document.

List<int> theList = new List<int>();
int theID = theDoc.AddImageUrl("");
while (true) {
  if (!theDoc.Chainable(theID))
  theDoc.Page = theDoc.AddPage();
  theID = theDoc.AddImageToChain(theID);

[Visual Basic]
Dim theList As List(Of Integer) = New List(Of Integer)
Dim theID As Integer
theID = theDoc.AddImageUrl("")
While True
  If Not theDoc.Chainable(theID) Then
    Exit While
  End If
  theDoc.Page = theDoc.AddPage()
  theID = theDoc.AddImageToChain(theID)
End While

The URL we've referenced makes extensive use of named destinations. We want these named destination links to take us between pages on the PDF rather than taking us to the original URL.

After adding the pages, we can flatten them. We can't do this until after the pages have been added because flattening will invalidate our previous ID and break the chain.

for (int i = 1; i <= theDoc.PageCount; i++) {
  theDoc.PageNumber = i;

[Visual Basic]
For i As Integer = 1 To theDoc.PageCount
  theDoc.PageNumber = i

Finally, we save.


[Visual Basic]

We get the following output. The links work within the PDF.

linkpages.pdf [Page 1]

linkpages.pdf [Page 2]