This sample code demonstrates how to set URL link to rectangle text area in the existing PDF document
This example teaches how to open existing PDF and set hyperlink URL to the rectangle area in text and then save modified PDF as new using ByteScout PDF SDK for NET
Program.vb:
VB
'******************************************************************* ' ByteScout PDF SDK ' ' Copyright © 2016 Bytescout, https://bytescout.com ' ALL RIGHTS RESERVED ' '******************************************************************* Imports Bytescout.PDF ''' <summary> ''' This example demonstrates how to create URI (link) action. ''' </summary> Class Program Shared Sub Main() ' Create new document Dim pdfDocument = New Document() pdfDocument.RegistrationName = "demo" pdfDocument.RegistrationKey = "demo" ' Add page Dim page = New Page(PaperFormat.A4) pdfDocument.Pages.Add(page) ' Add button Dim button = New PushButton(20, 20, 150, 25, "button1") button.Caption = "BYTESCOUT.COM" ' Add URI action Dim action = New URIAction(New Uri("https://bytescout.com/")) button.OnActivated = action page.Annotations.Add(button) ' Save document to file pdfDocument.Save("result.pdf") ' Cleanup pdfDocument.Dispose() ' Open document in default PDF viewer app Process.Start("result.pdf") End Sub End Class
Program.cs:
C#
//******************************************************************* // ByteScout PDF SDK // // Copyright © 2016 ByteScout - https://bytescout.com // ALL RIGHTS RESERVED // //******************************************************************* using System; using System.Diagnostics; using Bytescout.PDF; namespace UriAction { /// <summary> /// This example demonstrates how to create URI (link) action. /// </summary> class Program { static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Add page Page page = new Page(PaperFormat.A4); pdfDocument.Pages.Add(page); // Add button PushButton button = new PushButton(20, 20, 150, 25, "button1"); button.Caption = "BYTESCOUT.COM"; // Add URI action URIAction action = new URIAction(new Uri("https://bytescout.com/")); button.OnActivated = action; page.Annotations.Add(button); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open document in default PDF viewer app Process.Start("result.pdf"); } } }