FileDocCategorySizeDatePackage
Hyperlinks.javaAPI DocApache Poi 3.0.13609Thu May 31 18:45:30 BST 2007org.apache.poi.hslf.examples

Hyperlinks

public class Hyperlinks extends Object
Demonstrates how to read hyperlinks from a presentation
author
Yegor Kozlov

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        for (int i = 0; i < args.length; i++) {
            FileInputStream is = new FileInputStream(args[i]);
            SlideShow ppt = new SlideShow(is);
            is.close();

            Slide[] slide = ppt.getSlides();
            for (int j = 0; j < slide.length; j++) {
                System.out.println("slide " + slide[j].getSlideNumber());

                //read hyperlinks from the slide's text runs
                System.out.println("reading hyperlinks from the text runs");
                TextRun[] txt = slide[j].getTextRuns();
                for (int k = 0; k < txt.length; k++) {
                    String text = txt[k].getText();
                    Hyperlink[] links = txt[k].getHyperlinks();
                    if(links != null) for (int l = 0; l < links.length; l++) {
                        Hyperlink link = links[l];
                        String title = link.getTitle();
                        String address = link.getAddress();
                        System.out.println("  " + title);
                        System.out.println("  " + address);
                        String substring = text.substring(link.getStartIndex(), link.getEndIndex()-1);//in ppt end index is inclusive
                        System.out.println("  " + substring);
                    }
                }

                //in PowerPoint you can assign a hyperlink to a shape without text,
                //for example to a Line object. The code below demonstrates how to
                //read such hyperlinks
                System.out.println("  reading hyperlinks from the slide's shapes");
                Shape[] sh = slide[j].getShapes();
                for (int k = 0; k < sh.length; k++) {
                    Hyperlink link = sh[k].getHyperlink();
                    if(link != null)  {
                        String title = link.getTitle();
                        String address = link.getAddress();
                        System.out.println("  " + title);
                        System.out.println("  " + address);
                    }
                }
            }

        }