Hyperlink

Hyperlink (2)

Thursday, 29 August 2019 08:11

Add Hyperlinks to Images in PowerPoint in Java

Written by support iceblue

This article demonstrates how to add a hyperlink to an image in a PowerPint slide using Spire.Presentation for Java.

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.geom.Rectangle2D;

public class AddHyperlinkToImage {

    public static void main(String[] args) throws Exception {

        //create a Presentation object
        Presentation presentation = new Presentation();

        //get the first slide
        ISlide slide = presentation.getSlides().get(0);

        //add an image to slide
        String imaPath = "C:\\Users\\Administrator\\Desktop\\logo.png";
        Rectangle2D.Float rect = new Rectangle2D.Float(50, 50, 220, 60);
        IEmbedImage image = slide.getShapes().appendEmbedImage(ShapeType.RECTANGLE, imaPath, rect);

        //set the line of image shape to none
        image.getLine().setFillType(FillFormatType.NONE);

        //add a hyperlink to image
        ClickHyperlink hyperlink = new ClickHyperlink("https://www.e-iceblue.com");
        image.setClick(hyperlink);

        //save the file
        presentation.saveToFile("output/ImageHyperLink.pptx", FileFormat.PPTX_2013);
    }
}

Add Hyperlinks to Images in PowerPoint in Java

Thursday, 10 January 2019 07:52

Add Hyperlinks to a PowerPoint slide in Java

Written by support iceblue

This article demonstrate how to add hyperlinks to a PowerPoint slide using Spire.Presentation for Java.

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.geom.Rectangle2D;

public class AddHyperlink {
    public static void main(String[] args) throws Exception {
        //Create a Presentation instance
        Presentation presentation = new Presentation();

        //Add a shape 
        Rectangle2D.Double rec = new Rectangle2D.Double(presentation.getSlideSize().getSize().getWidth() / 2 - 255, 120, 300, 150);
        IAutoShape shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, rec);
        shape.getFill().setFillType(FillFormatType.NONE);
        shape.getLine().setWidth(0);
        shape.getTextFrame().getParagraphs().clear();

        //Add some paragraphs with hyperlinks to the shape
        ParagraphEx para1 = new ParagraphEx();
        PortionEx tr1 = new PortionEx();
        tr1.setText("Spire.Presentation for Java");
        tr1.getClickAction().setAddress("https://www.e-iceblue.com/Introduce/presentation-for-java.html");
        tr1.setLatinFont(new TextFont("Lucida Sans Unicode"));
        tr1.setFontHeight(20);
        para1.getTextRanges().append(tr1);
        shape.getTextFrame().getParagraphs().append(para1);
        shape.getTextFrame().getParagraphs().append(new ParagraphEx());

        ParagraphEx para2 = new ParagraphEx();
        PortionEx tr2 = new PortionEx();
        tr2.setText("Spire.Presentation for .NET");
        tr2.getClickAction().setAddress("https://www.e-iceblue.com/Introduce/presentation-for-net-introduce.html");
        tr2.setLatinFont(new TextFont("Lucida Sans Unicode"));
        tr2.setFontHeight(20);
        para2.getTextRanges().append(tr2);
        shape.getTextFrame().getParagraphs().append(para2);

        //Save the document
        presentation.saveToFile("AddHyperlink.pptx", FileFormat.PPTX_2010);
    }
}

Output:

Add Hyperlinks to a PowerPoint slide in Java