Text Box with Hyperlink using Apache POI and Aspose.Slides
Contents
[
Hide
]
Aspose.Slides - Text Box with Hyperlink
Please follow the steps below to create a TextBox with Hyperlink by using Aspose.Slides for Java API:
- Create an instance of Presentation.
- Obtain the reference of the first slide in the presentation.
- Add an AutoShape with ShapeType as Rectangle at a specified position of the slide and obtain the reference of that newly added AutoShape object.
- Add a TextFrame to the AutoShape.
- Instantiate the IHyperlinkManager.
- Assign the IHyperlinkManager object to the HLinkClick property associated with the desired portion of the TextFrame.
- Finally, save the PPTX file using the Presentation object
// Add an AutoShape of Rectangle Type
IShape pptxShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 150, 150, 150, 50);
// Cast the shape to AutoShape
IAutoShape pptxAutoShape = (IAutoShape) pptxShape;
// Access ITextFrame associated with the AutoShape
pptxAutoShape.addTextFrame("");
ITextFrame ITextFrame = pptxAutoShape.getTextFrame();
// Add some text to the frame
ITextFrame.getParagraphs().get_Item(0).getPortions().get_Item(0).setText("Aspose.Slides");
// Set Hyperlink for the portion text
IHyperlinkManager HypMan = ITextFrame.getParagraphs().get_Item(0)
.getPortions().get_Item(0).getPortionFormat().getHyperlinkManager();
HypMan.setExternalHyperlinkClick("http://www.aspose.com");
Apache POI SL - HSLF XSLF - Text Box with Hyperlink
XSLFTextBox and XSLFHyperlink can be used for textbox with Hyperlink as mentioned below:
// assign a hyperlink to a text run
XSLFTextBox shape = slide.createTextBox();
XSLFTextRun r = shape.addNewTextParagraph().addNewTextRun();
r.setText("Apache POI");
XSLFHyperlink link = r.createHyperlink();
link.setAddress("http://poi.apache.org");
Download Running Code
Download Sample Code
For more details, visit Creating TextBox with Hyperlink.