To know more about how to add text at a specific location in a PDF document, please consult the "Add Text At A Specific Location" example.
The following example demonstrates how to add an hyperlink on a specific word of a document. It also covers how to stylize the resulting link & add the created link to a link collection.
| Add hyperlinks on specific words of a page (C#) |
Copy Code |
|---|---|
public static void AddHyperlinks() { Console.WriteLine( "=== ADD HYPERLINKS ===" ); var outputFileName = "AddHyperlinks.pdf"; var outputPath = HyperlinksSample.HyperlinksSampleOutputDirectory + outputFileName; // Create a pdf document. using( var pdfoutput = PdfDocument.Create( outputPath ) ) { // Get the first page. var page = pdfoutput.Pages.First(); // Add Title. var titleStyle = TextStyle.WithFont( pdfoutput.Fonts.GetStandardFont( StandardFontType.Helvetica ), 15d ); page.AddParagraph( "Add hyperlinks", titleStyle, new ParagraphStyle( ParagraphHorizontalAlignment.Center ) ); // Add text. var textStyle = TextStyle.WithFont( titleStyle.Font, 12 ); page.AddText( "The word XCEED points to a website.", new Point( 75, 100 ), textStyle ); // Create a new Hyperlink around the previous XCEED word and add it to the page Hyperlink Collection for the page. var hyperlink = new Hyperlink( "www.xceed.com", new Rectangle( 127, 94, 45, 20 ) ); hyperlink.Border.Color = Color.Orange; hyperlink.Border.Width = 3; hyperlink.Border.Style = BorderStyle.Underline; page.Hyperlinks.Add( hyperlink ); // Save the output document. pdfoutput.Save(); Console.WriteLine( $"Created: {outputFileName}" ); } } | |
To know more about how to add text at a specific location in a PDF document, please consult the "Add Text At A Specific Location" example.