The example demonstrates how to create a navigation link to a page using ByteScout PDF SDK.
Program.vb:
VB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | '******************************************************************* ' ByteScout PDF SDK ' ' Copyright © 2016 Bytescout, https://bytescout.com ' ALL RIGHTS RESERVED ' '******************************************************************* Imports System.Drawing Imports Bytescout.PDF ''' <summary> ''' This example demonstrates how to create a navigation link to a page. ''' </summary> Class Program Shared Sub Main() ' Create new document Dim pdfDocument = New Document() pdfDocument.RegistrationName = "demo" pdfDocument.RegistrationKey = "demo" ' Add two pages Dim page1 = New Page(PaperFormat.A4) pdfDocument.Pages.Add(page1) Dim page2 = New Page(PaperFormat.A4) pdfDocument.Pages.Add(page2) Dim font = New Bytescout.PDF.Font(StandardFonts.Times, 12) Dim brush = New Bytescout.PDF.SolidBrush() ' Create link annotation pointing to Page 2, 200 Points from the top. Dim destination = New Destination(page2, 200) Dim link = New LinkAnnotation(destination, 20, 20, 100, 25) link.Color = New ColorRGB(255, 0, 0) ' you can change the link color page1.Annotations.Add(link) ' Draw link text (optional) page1.Canvas.DrawString( "Link to Page 2" , font, brush, New RectangleF(20, 20, 100, 25), New Bytescout.PDF.StringFormat() With {.HorizontalAlign = HorizontalAlign.Center, .VerticalAlign = VerticalAlign.Center}) ' Draw a text at the link target page2.Canvas.DrawString( "Link target" , font, brush, 20, 200) ' 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#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | //******************************************************************* // ByteScout PDF SDK // // Copyright © 2016 ByteScout - https://bytescout.com // ALL RIGHTS RESERVED // //******************************************************************* using System.Diagnostics; using System.Drawing; using Bytescout.PDF; using Brush = Bytescout.PDF.Brush; using Font = Bytescout.PDF.Font; using SolidBrush = Bytescout.PDF.SolidBrush; using StringFormat = Bytescout.PDF.StringFormat; namespace LinkToPage { /// <summary> /// This example demonstrates how to create a navigation link to a page. /// </summary> class Program { static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo" ; pdfDocument.RegistrationKey = "demo" ; // Add two pages Page page1 = new Page(PaperFormat.A4); pdfDocument.Pages.Add(page1); Page page2 = new Page(PaperFormat.A4); pdfDocument.Pages.Add(page2); Font font = new Font(StandardFonts.Times, 12); Brush brush = new SolidBrush(); // Create link annotation pointing to Page 2, 200 Points from the top. Destination destination = new Destination(page2, 200); LinkAnnotation link = new LinkAnnotation(destination, 20, 20, 100, 25); link.Color = new ColorRGB(255, 0, 0); // you can change the link color page1.Annotations.Add(link); // Draw link text (optional) page1.Canvas.DrawString( "Link to Page 2" , font, brush, new RectangleF(20, 20, 100, 25), new StringFormat {HorizontalAlign = HorizontalAlign.Center, VerticalAlign = VerticalAlign.Center}); // Draw a text at the link target page2.Canvas.DrawString( "Link target" , font, brush, 20, 200); // Save document to file pdfDocument.Save( "result.pdf" ); // Cleanup pdfDocument.Dispose(); // Open document in default PDF viewer app Process.Start( "result.pdf" ); } } } |