Hyperlinks

Presentations are usually not just static representations of content. Often they are interactive, and the interactivity is provided through various click and hover actions (ActionSettings).

The following example shows how you can create and customize VisualDrawing.Action and TextCharacterFormat.Action using the GemBox.Presentation API.

PowerPoint hyperlinks created with GemBox.Presentation
Screenshot of PowerPoint hyperlinks created with GemBox.Presentation
using System.IO;
using GemBox.Presentation;
using GemBox.Presentation.Media;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = new PresentationDocument();

        // Create first presentation slide.
        var slide = presentation.Slides.AddNew(SlideLayoutType.Custom);

        // Create first shape.
        var shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 2, 2, 8, 3, LengthUnit.Centimeter);

        // Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray));

        // Create a paragraph.
        var paragraph = shape.Text.AddParagraph();

        // Add and format paragraph plain text.
        var run = paragraph.AddRun("Powered by ");
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkGray));

        // Add and format paragraph hyperlink text.
        run = paragraph.AddRun("GemBox");
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkRed));
        run.Format.Action.Click.Set(ActionType.HyperlinkToWebPage, "http://www.gemboxsoftware.com/");

        // Create second presentation slide.
        slide = presentation.Slides.AddNew(SlideLayoutType.Custom);

        // Create first shape.
        shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 2, 2, 4, 3, LengthUnit.Centimeter);

        // Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray));

        // Set text run.
        run = shape.Text.AddParagraph().AddRun("Play Sound");
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkRed));

        // Set "play sound" action on created shape.
        var action = shape.Action.Click;
        using (var stream = File.OpenRead("%#Applause.wav%"))
            action.PlaySound(stream, "applause.wav");

        action.Set(ActionType.None);
        action.Highlight = true;

        // Create second shape.
        shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 7, 2, 4, 3, LengthUnit.Centimeter);

        // Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray));

        // Set text run.
        run = shape.Text.AddParagraph().AddRun("Hyperlink To Previous Slide");
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkRed));

        // Set "hyperlink to previous slide" action.
        shape.Action.Click.Set(ActionType.HyperlinkToPreviousSlide);

        // Create third shape.
        shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 12, 2, 4, 3, LengthUnit.Centimeter);

        // Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray));

        // Set text run.
        run = shape.Text.AddParagraph().AddRun("Hyperlink To Next Slide");
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkRed));

        // Set "hyperlink to next slide" action.
        shape.Action.Click.Set(ActionType.HyperlinkToNextSlide);

        // Create forth shape.
        shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 17, 2, 4, 3, LengthUnit.Centimeter);

        // Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray));

        // Set text run.
        run = shape.Text.AddParagraph().AddRun("Hyperlink To Web Page");
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkRed));

        // Set "hyperlink to web page" action.
        shape.Action.Click.Set(ActionType.HyperlinkToWebPage, "http://www.gemboxsoftware.com/");

        // Create third presentation slide.
        slide = presentation.Slides.AddNew(SlideLayoutType.Custom);

        presentation.Save("Hyperlinks.pptx");
    }
}
Imports System.IO
Imports GemBox.Presentation
Imports GemBox.Presentation.Media

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim presentation = New PresentationDocument

        ' Create first presentation slide.
        Dim slide = presentation.Slides.AddNew(SlideLayoutType.Custom)

        ' Create first shape.
        Dim shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 2, 2, 8, 3, LengthUnit.Centimeter)

        ' Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray))

        ' Create a paragraph.
        Dim paragraph = shape.Text.AddParagraph()

        ' Add and format paragraph plain text.
        Dim run = paragraph.AddRun("Powered by ")
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkGray))

        ' Add And format paragraph hyperlink text.
        run = paragraph.AddRun("GemBox")
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkRed))
        run.Format.Action.Click.Set(ActionType.HyperlinkToWebPage, "http://www.gemboxsoftware.com/")

        ' Create second presentation slide.
        slide = presentation.Slides.AddNew(SlideLayoutType.Custom)

        ' Create first shape.
        shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 2, 2, 4, 3, LengthUnit.Centimeter)

        ' Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray))

        ' Set text run.
        run = shape.Text.AddParagraph().AddRun("Play Sound")
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkRed))

        ' Set "play sound" action on created shape.
        Dim action = shape.Action.Click
        Using stream As Stream = File.OpenRead("%#Applause.wav%")
            action.PlaySound(stream, "applause.wav")
        End Using

        action.Set(ActionType.None)
        action.Highlight = True

        ' Create second shape.
        shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 7, 2, 4, 3, LengthUnit.Centimeter)

        ' Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray))

        ' Set text run.
        run = shape.Text.AddParagraph().AddRun("Hyperlink To Previous Slide")
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkRed))

        ' Set "hyperlink to previous slide" action.
        shape.Action.Click.Set(ActionType.HyperlinkToPreviousSlide)

        ' Create third shape.
        shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 12, 2, 4, 3, LengthUnit.Centimeter)

        ' Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray))

        ' Set text run.
        run = shape.Text.AddParagraph().AddRun("Hyperlink To Next Slide")
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkRed))

        ' Set "hyperlink to next slide" action.
        shape.Action.Click.Set(ActionType.HyperlinkToNextSlide)

        ' Create forth shape.
        shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 17, 2, 4, 3, LengthUnit.Centimeter)

        ' Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray))

        ' Set text run.
        run = shape.Text.AddParagraph().AddRun("Hyperlink To Web Page")
        run.Format.Fill.SetSolid(Color.FromName(ColorName.DarkRed))

        ' Set "hyperlink to web page" action.
        shape.Action.Click.Set(ActionType.HyperlinkToWebPage, "http://www.gemboxsoftware.com/")

        ' Create third presentation slide.
        slide = presentation.Slides.AddNew(SlideLayoutType.Custom)

        presentation.Save("Hyperlinks.pptx")
    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Presentation yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.