পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Saturday, January 14, 2017

Apache POI PPT - Creating Hyperlinks

In this chapter you will learn how to create hyperlinks in a presentation.

Creating Hyperlinks

You can read the hyperlinks in a presentation using the createHyperlink() method of the XSLFTextRun class. Follow the procedure given below to create a hyperlink in a presentation.

Create an empty presentation using the XMLSlideShow class as shown below:
XMLSlideShow ppt = new XMLSlideShow();
Create an empty slide and create a textbox and body of the slide using body and content layout.
//create an empty presentation
XSLFSlideMaster slideMaster = ppt.getSlideMasters()[0];

//creating a slide with title and content layout
XSLFSlideLayout slidelayout = slideMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
XSLFSlide slide = ppt.createSlide(slidelayout);

//selection of body place holder
XSLFTextShape body = slide.getPlaceholder(1);

//clear the existing text in the slide
body.clearText();
Create a text run object and set text to it as shown below:
XSLFTextRun textRun=body.addNewTextParagraph().addNewTextRun();
textRun.setText("Tutorials point");
Create a hyperlink using the createHyperlink() method of the XSLFTextRun class as shown below:
XSLFHyperlink link = textRun.createHyperlink();
Set the link address to the hyperlink using the setAddress() method of XSLFHyperlink class as shown below:
link.setAddress("http://www.tutorialspoint.com/");
Given below is the complete program to create hyperlink in a presentation:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.xslf.usermodel.SlideLayout;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFHyperlink;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
import org.apache.poi.xslf.usermodel.XSLFTextRun;
import org.apache.poi.xslf.usermodel.XSLFTextShape;

public class CreatingHyperlinks {

   public static void main(String args[]) throws IOException{
      
      //create an empty presentation
      XMLSlideShow ppt = new XMLSlideShow();
      
      //getting the slide master object
      XSLFSlideMaster slideMaster = ppt.getSlideMasters()[0];
      
      //select a layout from specified list
      XSLFSlideLayout slidelayout = slideMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
     
      //creating a slide with title and content layout
      XSLFSlide slide = ppt.createSlide(slidelayout);
      
      //selection of title place holder
      XSLFTextShape body = slide.getPlaceholder(1);
      
      //clear the existing text in the slid
      body.clearText();
      
      //adding new paragraph
      XSLFTextRun textRun = body.addNewTextParagraph().addNewTextRun();
      
      //setting the text
      textRun.setText("Tutorials point"); 
      
      //creating the hyperlink
      XSLFHyperlink link = textRun.createHyperlink();
      
      //setting the link address
      link.setAddress("http://www.tutorialspoint.com/");
      
      //create the file object            
      File file=new File("hyperlink.pptx");
      FileOutputStream out = new FileOutputStream(file);
      
      //save the changes in a file
      ppt.write(out);
      System.out.println("slide cretated successfully");
      out.close();              
   }
}
Save the above Java code as CreatingHyperlinks.java, and then compile and execute it from the command prompt as follows:
$javac CreatingHyperlinks.java
$java CreatingHyperlinks
It will compile and execute to generate the following output:
slide cretated successfully 
The newly added slide with the hyperlink in its body looks as follows:
Create Hyperlink

No comments:

Post a Comment