We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to Add HTML Text to Slide and Set Font Style?

Hi Team,

Could you please help me with a sample code to

  • Insert a text box in a presentation
  • Add a html text to the text box with hyperlink
  • And the text for the hyperlink must be of font style Arial and size 8 pts.

Thanks,
Thilak

@Thilakbabu,
Thank you for posting the inquiry.

To perform this sequence, you should add a rectangle autoshape, add an HTML text into a paragraph collection contained in an autoshape’s text frame, and set formatting options for the new paragraph. The following code snippet shows you how to do this:

// Add an empty transparent text box to a slide.
IAutoShape autoShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 200, 100);
autoShape.getFillFormat().setFillType(FillType.NoFill);
autoShape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
autoShape.getTextFrame().getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
autoShape.getTextFrame().getParagraphs().clear();

// Add some HTML text to the shape.
String htmlData = "<a href=\"https://www.aspose.com/\">Aspose Website</a>";
autoShape.getTextFrame().getParagraphs().addFromHtml(htmlData);

// Set the text format for the HTML text.
IParagraph lastParagraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
lastParagraph.getParagraphFormat().getDefaultPortionFormat().setLatinFont(new FontData("Arial"));
lastParagraph.getParagraphFormat().getDefaultPortionFormat().setFontHeight(8);

Documents:
Manage TextBox
Manage Paragraph
Text Formatting

API Reference:
addAutoShape Method
addFromHtml Method
IParagraphFormat Interface

If you fail to do so, please share your example HTML text.