Hi Team,
When I try to add a html string to a text box, the string content is getting displayed outside the text box got created.
see the below screenshot
image.png (24.2 KB)
similarly the next textbox underneath it which has html tags.
image.png (28.2 KB)
Please find the code snippet I have used for the same
Presentation pres = new Presentation();
pres.getSlideSize().setSize((float) 960, (float) 540,
SlideSizeScaleType.DoNotScale);
try {
// Gets the first slide in the presentation
ISlide sld = pres.getSlides().get_Item(0);
createTitleCard(sld);
createGoBackCard(sld);
createSummaryCard(sld);
// Saves the presentation to disk
pres.save("TextBoxesThroughAspose.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
private static void createTitleCard(ISlide sld) {
// Adds an AutoShape with type set as Rectangle
IAutoShape textBox = sld.getShapes().addAutoShape(ShapeType.Rectangle, 0, 0, 960, 15);
textBox.getFillFormat().setFillType(FillType.NoFill);
textBox.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
// Accesses the text frame
ITextFrame tf = textBox.getTextFrame();
tf.getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
tf.getParagraphs().get_Item(0).getParagraphFormat().setAlignment(TextAlignment.Left);
// Creates the Paragraph object for text frame
IParagraph para = tf.getParagraphs().get_Item(0);
// Creates a Portion object for paragraph
IPortion portion = para.getPortions().get_Item(0);
IParagraphFormat paragraphFormat = para.getParagraphFormat();
applyFontStyle(paragraphFormat);
// Sets Text
portion.setText("Title TextBox");
}
private static void applyFontStyle(IParagraphFormat paragraphFormat) {
IBasePortionFormat portionFormat = paragraphFormat.getDefaultPortionFormat();
portionFormat.setFontHeight(10);
portionFormat.setLatinFont(new FontData("Montserrat"));
portionFormat.getFillFormat().setFillType(FillType.Solid);
portionFormat.getFillFormat().getSolidFillColor().setColor(Color.decode("#151921"));
}
private static void createGoBackCard(ISlide sld) {
// Adds an AutoShape with type set as Rectangle
IAutoShape textBox = sld.getShapes().addAutoShape(ShapeType.Rectangle, 0, 16, 960, 15);
textBox.getFillFormat().setFillType(FillType.NoFill);
textBox.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
// Accesses the text frame
ITextFrame tf = textBox.getTextFrame();
tf.getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
tf.getParagraphs().get_Item(0).getParagraphFormat().setAlignment(TextAlignment.Left);
IParagraphCollection paragraphCollection = tf.getParagraphs();
paragraphCollection.addFromHtml("Go Back");
IParagraph paragraph = paragraphCollection.get_Item(paragraphCollection.getCount() - 1);
IParagraphFormat paragraphFormat = paragraph.getParagraphFormat();
paragraphFormat.getDefaultPortionFormat().getHyperlinkManager()
.setExternalHyperlinkClick("http://google.com");
applyFontStyle(paragraphFormat);
}
private static void createSummaryCard(ISlide sld) {
// Adds an AutoShape with type set as Rectangle
IAutoShape textBox = sld.getShapes().addAutoShape(ShapeType.Rectangle, 0, 32, 960, 15);
textBox.getFillFormat().setFillType(FillType.NoFill);
textBox.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
// Accesses the text frame
ITextFrame tf = textBox.getTextFrame();
tf.getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
tf.getParagraphs().get_Item(0).getParagraphFormat().setAlignment(TextAlignment.Left);
IParagraphCollection paragraphCollection = tf.getParagraphs();
paragraphCollection.addFromHtml("<b>Hi</b> This is <b>Summmmaarrryyy</b>");
IParagraph paragraph = paragraphCollection.get_Item(paragraphCollection.getCount() - 1);
IParagraphFormat paragraphFormat = paragraph.getParagraphFormat();
applyFontStyle(paragraphFormat);
}
But able to achieve the multiple text boxes with hyperlink and bold tags manually without any issues. Only with aspose, the text content coming outside the text box.
image.png (20.0 KB)
Attaching the pptx file created from aspose and manually created pptx file.Aspose-textbox-issue.zip (45.7 KB)
Please help us resolving this issue ASAP.
Thanks,
Thilak