--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.hslf.examples;\r
+\r
+import org.apache.poi.hslf.usermodel.SlideShow;\r
+import org.apache.poi.hslf.usermodel.RichTextRun;\r
+import org.apache.poi.hslf.model.*;\r
+\r
+import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\r
+import java.awt.*;\r
+\r
+/**\r
+ * Demonstrates how to create hyperlinks in PowerPoint presentations\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class CreateHyperlink {\r
+\r
+ public static void main(String[] args) throws Exception {\r
+ SlideShow ppt = new SlideShow();\r
+\r
+ Slide slide = ppt.createSlide();\r
+\r
+ TextBox shape = new TextBox();\r
+ shape.setText("Apache POI");\r
+ Rectangle anchor = new Rectangle(100, 100, 200, 50);\r
+ shape.setAnchor(anchor);\r
+\r
+ String text = shape.getText();\r
+ Hyperlink link = new Hyperlink();\r
+ link.setAddress("http://www.apache.org");\r
+ link.setTitle(shape.getText());\r
+ int linkId = ppt.addHyperlink(link);\r
+\r
+ shape.setHyperlink(linkId, 0, text.length());\r
+\r
+ slide.addShape(shape);\r
+\r
+ FileOutputStream out = new FileOutputStream("hyperlink.ppt");\r
+ ppt.write(out);\r
+ out.close();\r
+\r
+ }\r
+}\r
return (OEPlaceholderAtom)getClientDataRecord(RecordTypes.OEPlaceholderAtom.typeID);
}
+ /**
+ *
+ * Assigns a hyperlink to this text shape
+ *
+ * @param linkId id of the hyperlink, @see org.apache.poi.hslf.usermodel.SlideShow#addHyperlink(Hyperlink)
+ * @param beginIndex the beginning index, inclusive.
+ * @param endIndex the ending index, exclusive.
+ * @see org.apache.poi.hslf.usermodel.SlideShow#addHyperlink(Hyperlink)
+ */
+ public void setHyperlink(int linkId, int beginIndex, int endIndex){
+ //TODO validate beginIndex and endIndex and throw IllegalArgumentException
+
+ InteractiveInfo info = new InteractiveInfo();
+ InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
+ infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);
+ infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url);
+ infoAtom.setHyperlinkID(linkId);
+
+ _txtbox.appendChildRecord(info);
+
+ TxInteractiveInfoAtom txiatom = new TxInteractiveInfoAtom();
+ txiatom.setStartIndex(beginIndex);
+ txiatom.setEndIndex(endIndex);
+ _txtbox.appendChildRecord(txiatom);
+
+ }
+
}