SelectPdf for .NET - Pdf Internal and External Links - Html to Pdf Converter - VB.NET / ASP.NET MVC Sample

This sample shows how the html to pdf converter can handle internal and external links from the web page when converted to pdf using SelectPdf Pdf Library for .NET.

SelectPdf Library can convert internal html links to internal pdf links and keep external html links (hyperlinks to other pages) the same in pdf (external links). These links can be disabled in pdf if needed.

Test document

Url:


Convert with internal links
Convert with external links



Sample Code VB.NET



Imports SelectPdf

Namespace Controllers
    Public Class HtmlToPdfConverterLinksController
        Inherits Controller

        ' GET: HtmlToPdfConverterLinks
        Public Function Index() As ActionResult
            Dim url As String =
                System.Web.VirtualPathUtility.ToAbsolute("~/files/document.html")
            ViewData.Add("ViewTxtUrl", (New Uri(Request.Url, url)).AbsoluteUri)
            Return View()
        End Function

        <HttpPost>
        Public Function SubmitAction(collection As FormCollection) As ActionResult
            ' instantiate a html to pdf converter object
            Dim converter As New HtmlToPdf()

            ' set links options
            converter.Options.InternalLinksEnabled = collection("ChkInternalLinks") = "on"
            converter.Options.ExternalLinksEnabled = collection("ChkExternalLinks") = "on"

            ' create a new pdf document converting an url
            Dim doc As PdfDocument = converter.ConvertUrl(collection("TxtUrl"))

            ' save pdf document
            Dim pdf As Byte() = doc.Save()

            ' close pdf document
            doc.Close()

            ' return resulted pdf document
            Dim fileResult As FileResult = New FileContentResult(pdf, "application/pdf")
            fileResult.FileDownloadName = "Document.pdf"
            Return fileResult
        End Function
    End Class
End Namespace