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.
1. From the official website of E-iceblue Free Spire. Presentation for Java Download the free version.
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.
//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