Create hyperlinks in Java PowerPoint

This time I will show you how to create a hyperlink in PowerPoint. It also requires a library called Spire.Presentation for Java. Show me how to link to websites, email addresses, and other PowerPoint slides.

Preparation

1. From the official website of E-iceblue Free Spire. Presentation for Java Download the free version.

f:id:lendoris:20201230161324p:plain

2. Launch the IDE to create a new project, then add the appropriate Spire. Presentation.jar to the reference that was in the installed file.

f:id:lendoris:20201230161342p:plain

code

```java import com.spire.presentation.*; import com.spire.presentation.drawing.FillFormatType; import java.awt.*; import java.awt.geom.Rectangle2D; public class addHyperlink { public static void main(String[] args) throws Exception { String outputFile = "output/hyperlink_result.pptx"; //Create a PPT object Presentation presentation = new Presentation();
    //Add another slide at the end of the text.
    presentation.getSlides().append();
    Rectangle2D.Double rec = new Rectangle2D.Double(presentation.getSlideSize().getSize().getWidth() / 2 - 255, 120, 500, 280);
    IAutoShape shape = presentation.getSlides().get(1).getShapes().appendShape(ShapeType.RECTANGLE, rec);
    shape.getFill().setFillType(FillFormatType.NONE);
    shape.getLine().setWidth(0);
    ParagraphEx para1 = new ParagraphEx();
    PortionEx tr1 = new PortionEx();
    tr1.setText("Two pages");
    para1.getTextRanges().append(tr1);
    shape.getTextFrame().getParagraphs().append(para1);
    para1.setAlignment(TextAlignmentType.CENTER);
    tr1.getFill().setFillType(FillFormatType.SOLID);
    tr1.getFill().getSolidColor().setColor(Color.blue);
    shape.getTextFrame().getParagraphs().append(new ParagraphEx());

    //Add a shape on the first slide.
    IAutoShape shape1 = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, rec);
    shape1.getFill().setFillType(FillFormatType.NONE);
    shape1.getLine().setWidth(0);
    //Paste the link on your website.
    ParagraphEx para2 = new ParagraphEx();
    PortionEx tr2 = new PortionEx();
    tr2.setText("Please click");
    tr2.getClickAction().setAddress("www.google.com");
    para2.getTextRanges().append(tr2);
    shape1.getTextFrame().getParagraphs().append(para2);
    shape1.getTextFrame().getParagraphs().append(new ParagraphEx());
    ParagraphEx para3 = new ParagraphEx();
    PortionEx tr3 = new PortionEx();
    tr3.setText("Read the Japanese page");
    tr3.getClickAction().setAddress("www.google.com/");
    para3.getTextRanges().append(tr3);
    shape1.getTextFrame().getParagraphs().append(para3);
    shape1.getTextFrame().getParagraphs().append(new ParagraphEx());
    ParagraphEx para4 = new ParagraphEx();
    PortionEx tr4 = new PortionEx();
    tr4.setText("Go to Yahoo! Answers and ask a question");
    tr4.getClickAction().setAddress("www.google.com/");
    para4.getTextRanges().append(tr4);
    shape1.getTextFrame().getParagraphs().append(para4);
    shape1.getTextFrame().getParagraphs().append(new ParagraphEx());
    //Paste the link to your email address.
    ParagraphEx para5 = new ParagraphEx();
    PortionEx tr5 = new PortionEx();
    tr5.setText("Contact us by email");
    tr5.getClickAction().setAddress("mailto:[email protected]");
    para5.getTextRanges().append(tr5);
    shape1.getTextFrame().getParagraphs().append(para5);
    shape1.getTextFrame().getParagraphs().append(new ParagraphEx());
    //Add a hyperlink to jump to another slide.
    ParagraphEx para6 = new ParagraphEx();
    PortionEx tr6 = new PortionEx("Jump to the second slide");
    ClickHyperlink link = new ClickHyperlink(presentation.getSlides().get(1));
    tr6.setClickAction(link);
    para6.getTextRanges().append(tr6);
    shape1.getTextFrame().getParagraphs().append(para6);

    //you save.
    presentation.saveToFile(outputFile, FileFormat.PPTX_2010);
}

}

 <h4> <strong> Completion example </strong> </h4>
<p><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/l/lendoris/20201230/20201230161603.png " alt="f:id:lendoris:20201230161603p:plain" title="" class="hatena-fotolife" itemprop="image" /></p>
<p> </p>


Recommended Posts

Create hyperlinks in Java PowerPoint
Create JSON in Java
Create Azure Functions in Java
Insert footer in Java Powerpoint
Create variable length binary data in Java
Partization in Java
Changes in Java 11
Rock-paper-scissors in Java
Create Java Spring Boot project in IntelliJ
Create a TODO app in Java 7 Create Header
Pi in Java
FizzBuzz in Java
Create barcodes and QR codes in Java PDF
Create a CSR with extended information in Java
Try to create a bulletin board in Java
Let's create a super-simple web framework in Java
I tried to create Alexa skill in Java
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
NVL-ish guy in Java
Combine arrays in Java
Callable Interface in Java
[Java] Create a filter
Comments in Java source
Azure functions in java
Format XML in Java
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Type determination in Java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
POST JSON in Java
Express failure in Java
Date manipulation in Java 8
What's new in Java 8
Use PreparedStatement in Java
What's new in Java 9,10,11
Parallel execution in Java
Initializing HashMap in Java
How to create a Java environment in just 3 seconds
Java extracts text content of SmartArt shapes in PowerPoint
I tried to create a Clova skill in Java
How to create a data URI (base64) in Java
Try using RocksDB in Java
Read binary files in Java 1
Avoid Yubaba's error in Java
Get EXIF information in Java
Save Java PDF in Excel
[Neta] Sleep Sort in Java