News Category

Hyperlink

Hyperlink (6)

Hyperlinks in a PowerPoint file not only can be linked to external URLs, but also to the specific slide within the document. This article will show you how to create a hyperlink that links to a specified slide using Spire.Presentation.

Step 1: Create a PowerPoint file and append a slide to it.

Presentation presentation = new Presentation();
presentation.Slides.Append();

Step 2: Add a shape to the second slide.

IAutoShape shape = presentation.Slides[1].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(10, 50, 200, 50));
shape.TextFrame.Text = "Jump to the first slide"; 

Step 3: Create a hyperlink based on the shape and the text on it, linking to the first slide .

ClickHyperlink hyperlink = new ClickHyperlink(presentation.Slides[0]);
shape.Click = hyperlink;
shape.TextFrame.TextRange.ClickAction = hyperlink;

Step 4: Save the file.

presentation.SaveToFile("hyperlink.pptx", FileFormat.Pptx2010);

Output:

How to Link to a Specific Slide in PowerPoint in C#, VB.NET

Full Code:

[C#]
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace Link_to_a_Specific_Slide
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();
            presentation.Slides.Append();
            IAutoShape shape = presentation.Slides[1].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(10, 50, 200, 50));
            shape.Fill.FillType = FillFormatType.None;
            shape.Line.FillType = FillFormatType.None;
            shape.TextFrame.Text = "Jump to the first slide";
            ClickHyperlink hyperlink = new ClickHyperlink(presentation.Slides[0]);
            shape.Click = hyperlink;
            shape.TextFrame.TextRange.ClickAction = hyperlink;
            presentation.SaveToFile("output.pptx", FileFormat.Pptx2010);


        }
    }
}
[VB.NET]
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing
Namespace Link_to_a_Specific_Slide

	Class Program

		Private Shared Sub Main(args As String())
			Dim presentation As New Presentation()
			presentation.Slides.Append()
			Dim shape As IAutoShape = presentation.Slides(1).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(10, 50, 200, 50))
			shape.Fill.FillType = FillFormatType.None
			shape.Line.FillType = FillFormatType.None
			shape.TextFrame.Text = "Jump to the first slide"
			Dim hyperlink As New ClickHyperlink(presentation.Slides(0))
			shape.Click = hyperlink
			shape.TextFrame.TextRange.ClickAction = hyperlink
			presentation.SaveToFile("output.pptx", FileFormat.Pptx2010)


		End Sub
	End Class
End Namespace

Hyperlinks can direct readers to a web page, a file, an E-mail address, or other place in the same PowerPoint file. A hyperlink can be added to a text, an image or a shape. In the previous article, we've illustrated how to add hyperlink to text, this article is going to demonstrate how to add hyperlink to an image in PowerPoint using Spire.Presentation.

Detail steps:

Step 1: Initialize an object of Presentation class and Load the PowerPoint file.

Presentation presentation = new Presentation();
presentation.LoadFromFile("Input.pptx");

Step 2: Get the first slide.

ISlide slide = presentation.Slides[0];

Step 3: Add image to slide.

RectangleF rect = new RectangleF(50, 300, 100, 100);
IEmbedImage image = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, @"logo.png", rect);

Step 4: Add hyperlink to image.

ClickHyperlink hyperlink = new ClickHyperlink("https://www.e-iceblue.com");
image.Click = hyperlink;

Step 5: Save the file.

presentation.SaveToFile("ImageHyperLink.pptx", FileFormat.Pptx2010);

Screenshot:

Add Hyperlink to an Image in PowerPoint in C#

Full code:

using Spire.Presentation;
using System.Drawing;
namespace InitializeHyperlink
{

    class Program
    {

        static void Main(string[] args)
        {
            //Initialize an object of Presentation class
            Presentation presentation = new Presentation();
            //Load the PowerPoint file
            presentation.LoadFromFile("test.pptx");

            //Get the first slide
            ISlide slide = presentation.Slides[0];

            //Add image to slide
            RectangleF rect = new RectangleF(50, 300, 100, 100);
            IEmbedImage image = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, @"logo.png", rect);

            //Add hyperlink to image
            ClickHyperlink hyperlink = new ClickHyperlink("https://www.e-iceblue.com");
            image.Click = hyperlink;

            //Save the file
            presentation.SaveToFile("ImageHyperLink.pptx", FileFormat.Pptx2010);

        }
    }
}

With the help of Spire.Presentation, developers can insert new hyperlink into PowerPoint Presentation and edit the existing hyperlinks in C# and VB.NET. This article will show you how to add hyperlink to the existing text on presentation slides.

Firstly check the screenshot of the original presentation slides.

How to add hyperlink to the existing text on presentation slides in C#

Here comes to the steps of how to adding hyperlink to an existing text in Presentation slide:

Step 1: Create a new presentation document and load from file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

Step 2: Find the text we want to add link to it.

IAutoShape shape = ppt.Slides[0].Shapes[0] as IAutoShape;
TextParagraph tp = shape.TextFrame.TextRange.Paragraph;
string temp = tp.Text;

Step 3: Adding the hyperlink to the existing text.

//split the original text
string textToLink = "Spire.Presentation";
string[] strSplit = temp.Split(new string[] { "Spire.Presentation" }, StringSplitOptions.None);

//Clear all text
tp.TextRanges.Clear();

//Add new text
TextRange tr = new TextRange(strSplit[0]);
tp.TextRanges.Append(tr);

//Add the hyperlink
tr = new TextRange(textToLink);
tr.ClickAction.Address = "http://www.e-iceblue.com/Introduce/presentation-for-net-introduce.html";

tp.TextRanges.Append(tr);

Step 4: Save the document to file.

ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

Effective screenshot after adding the hyperlink to the existing text:

How to add hyperlink to the existing text on presentation slides in C#

Full codes:

using Spire.Presentation;
using System;
namespace AddHyperlink
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

            IAutoShape shape = ppt.Slides[0].Shapes[0] as IAutoShape;
            TextParagraph tp = shape.TextFrame.TextRange.Paragraph;
            string temp = tp.Text;

            //split the original text
            string textToLink = "Spire.Presentation";
            string[] strSplit = temp.Split(new string[] { "Spire.Presentation" }, StringSplitOptions.None);

            //Clear all text
            tp.TextRanges.Clear();

            //Add new text
            TextRange tr = new TextRange(strSplit[0]);
            tp.TextRanges.Append(tr);

            //Add the hyperlink
            tr = new TextRange(textToLink);
            tr.ClickAction.Address = "http://www.e-iceblue.com/Introduce/presentation-for-net-introduce.html";

            tp.TextRanges.Append(tr);

            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

        }
    }
}

In the previous topic, we discussed about how to insert hyperlink into PowerPoint presentation. In this topic, we will show you how to remove the hyperlink on a slide in the presentation by using the Spire.Presentation in C#.

Firstly, view the hyperlinks on a slide that we need to remove later.

How to remove the hyperlink on a slide in the presentation

Here comes to the steps of how to remove the hyperlinks in the PowerPoint presentation in C#.

Step 1: Create Presentation instance and load file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

Step 2: Get the shape and its text with hyperlink.

IAutoShape shape = ppt.Slides[0].Shapes[1] as IAutoShape;

Step 3: Set the ClickAction property into null to remove the hyperlink.

shape.TextFrame.TextRange.ClickAction = null;

Step 4: Save the document to file.

ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

Effective screenshot after removing the first hyperlink:

How to remove the hyperlink on a slide in the presentation

Full codes:

using Spire.Presentation;
namespace RemoveHyperlink
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

            IAutoShape shape = ppt.Slides[0].Shapes[1] as IAutoShape;
            shape.TextFrame.TextRange.ClickAction = null;

            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

        }
    }
}

Hyperlinks can easily guide the readers to the place you want to point to and it displays large amount of information to readers. Spire.Presentation for .NET enables developers to insert hyperlinks in PowerPoint presentations. Developers can also modify the existing hyperlinks and replace with new link text or target URL. This section will show how to edit hyperlinks from presentation slides in C#. Firstly check the screenshot of the original hyperlink:

Modify hyperlinks in PowerPoint documents

Spire.Presentation offers a ClickAction class for users to edit the hyperlinks. You can call the function ClickHyperlink to edit the hyperlinks. Here comes to the steps.

Step 1: Load a PowerPoint documents with hyperlinks.

Presentation pre = new Presentation();
pre.LoadFromFile(@"..\..\sample.pptx");

Step 2: Find the hyperlinks you want to edit.

IAutoShape shape = (IAutoShape)pre.Slides[0].Shapes[2];

Step 3: Edit the link text and the target URL.

shape.TextFrame.TextRange.ClickAction.Address = "http://www.e-iceblue.com";
shape.TextFrame.TextRange.Text = "E-iceblue";

Step 4: Save the document.

pre.SaveToFile(@"..\..\result.pptx",FileFormat.Pptx2010);

Effective screenshot after edit the hyperlink on presentation slide:

Modify hyperlinks in PowerPoint documents

Full codes:

namespace EditHyperlink
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation pre = new Presentation();
            pre.LoadFromFile(@"..\..\sample.pptx");
            IAutoShape shape = (IAutoShape)pre.Slides[0].Shapes[2];
            shape.TextFrame.TextRange.ClickAction.Address = "http://www.e-iceblue.com";
            shape.TextFrame.TextRange.Text = "E-iceblue";
            pre.SaveToFile(@"..\..\result.pptx",FileFormat.Pptx2010);
            System.Diagnostics.Process.Start(@"..\..\result.pptx");
        }
    }
}

A hyperlink is a clickable element, typically embedded within text or images, which allows users to navigate and access different webpages, documents, or resources. By adding hyperlinks in a PowerPoint presentation, users are able to easily visit related content while viewing or showing the slides, enhancing convenience during the presentation. In this article, we will show you how to add hyperlink to PowerPoint Presentation programmatically by using Spire.Presentation for .NET.

Install Spire.Presentation for .NET

To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Presentation

Add Hyperlink to Text on Slide

Spire.Presentation for .NET allows users to insert hyperlink to text on slides easily by using TextRange.ClickAction.Address property. The following are detailed steps.

  • Create a new PowerPoint presentation.
  • Load a PowerPoint file using Presentation.LoadFromFile() method.
  • Get the first slide using Presentation.Slides[] property.
  • Add a rectangle shape to the slide by using ISlide.Shapes.AppendShape() method.
  • Remove the default paragraphs in the shape.
  • Create a TextParagraph instance to represent a text paragraph.
  • Create a TextRange instance to represent a text range and set link address for it by TextRange.ClickAction.Address property.
  • Create an another TextRange instance to represent the rest of the text.
  • Append text ranges to paragraph using TextParagraph.TextRanges.Append() method.
  • Append the paragraph to the shape using IAutoShape.TextFrame.Paragraphs.Append() method.
  • Loop through all text ranges in each paragraph and set font for them.
  • Save the result file using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace Hyperlink
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation presentation = new Presentation();

            //Load the PowerPoint file
            presentation.LoadFromFile("sample.pptx", FileFormat.Pptx2010);

            //Get the first slide of the presentation
            ISlide slide = presentation.Slides[0];

            //Add a shape to the slide
            RectangleF rec = new RectangleF(presentation.SlideSize.Size.Width / 2 - 120, 200, 500, 150);
            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, rec);
            shape.Fill.FillType = FillFormatType.None;
            shape.ShapeStyle.LineColor.Color = Color.White;

            //Remove the default paragraphs in the shape
            shape.TextFrame.Paragraphs.Clear();

            //Create a TextParagraph instance
            TextParagraph para = new TextParagraph();

            //Create a TextRange instance
            TextRange tr = new TextRange("Spire.Presentation for .NET");

            //Set a hyperlink address for the text range
            tr.ClickAction.Address = "http://www.e-iceblue.com/Introduce/presentation-for-net-introduce.html";

            //Append the text range to the paragraph
            para.TextRanges.Append(tr);

            //Create a TextRange instance
            tr = new TextRange("is a professional PowerPoint® compatible API that enables developers to create, read,  modify, convert and Print PowerPoint documents on any .NET platform."
                +"As an independent PowerPoint .NET API, Spire.Presentation for .NET doesn't need Microsoft PowerPoint to be installed on machines.");

            //Append the text range to the paragraph
            para.TextRanges.Append(tr);

            //Append the paragraph to the shape
            shape.TextFrame.Paragraphs.Append(para);

            //Loop through the paragraphs in the shape
            foreach (TextParagraph textPara in shape.TextFrame.Paragraphs)
            {
                if (!string.IsNullOrEmpty(textPara.Text))
                {

                    //Loop through the text ranges in each paragraph
                    foreach (TextRange textRange in textPara.TextRanges)
                    {

                        //Set font
                        textRange.LatinFont = new TextFont("Calibri");
                        textRange.FontHeight = 24;
                        textRange.Fill.FillType = FillFormatType.Solid;
                        textRange.Fill.SolidColor.Color = Color.Black;
                    }
                }
            }

            //Save the presentation
            presentation.SaveToFile("TextHyperlink.pptx", FileFormat.Pptx2013);
            presentation.Dispose();
        }
    }
}

C#/VB.NET: Add Hyperlink to PowerPoint Presentation

Add Hyperlink to Image on Slide

Spire.Presentation for .NET also supports adding a hyperlink to an image. You can create a hyperlink by using  ClickHyperlink class and then add the hyperlink to the image using the IEmbedImage.Click property. The related steps are as follows.

  • Create a new PowerPoint presentation.
  • Load a PowerPoint file using Presentation.LoadFromFile() method.
  • Get the second slide by using Presentation.Slides[] property.
  • Add a image to the slide using ISlide.Shapes.AppendEmbedImage() method.
  • Create a ClickHyperlink object and append the hyperlink to added image using IEmbedImage.Click property.
  • Save the result file using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;
using System.Drawing;
namespace ImageHyperlink
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an object of Presentation class
            Presentation presentation = new Presentation();

            //Load the PowerPoint file
            presentation.LoadFromFile("TextHyperlink.pptx", FileFormat.Pptx2010);

            //Get the second slide of the presentation
            ISlide slide = presentation.Slides[1];

            //Add a image to slide
            RectangleF rect = new RectangleF(100, 50, 150, 150);
            IEmbedImage image = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, @"logo.png", rect);

            //Add hyperlink to image
            ClickHyperlink hyperlink = new ClickHyperlink("http://www.e-iceblue.com/Introduce/presentation-for-net-introduce.html");
            image.Click = hyperlink;

            //Save the result file
            presentation.SaveToFile("ImageHyperlink.pptx", FileFormat.Pptx2010);
            presentation.Dispose();
        }
    }
} 

C#/VB.NET: Add Hyperlink to PowerPoint Presentation

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.