Hello,
I used to import com.aspose.slides.TextHolder in a very old version, but it failed now while update the aspose to latest version. Is there still has TextHolder class and if not what is the replacement?
Hi Jiang,
I have observed your comments and like to share that in new API every text containing element is an AutoShape. You need to use AutoShape to serve the purpose. Please visit this documentation link for your further kind reference in this regard.
Many Thanks,
Thanks for your reply. The usage the TextHolder looks like below:
private String getText(Shape shape) {
if (shape.isTextHolder()) {
return ((TextHolder)shape.getPlaceholder()).getText();
} else {
return shape.getTextFrame().getText();
}
}
private Paragraphs getParagraphs(Shape shape) {
if (shape.isTextHolder()) {
TextHolder textHolder = (TextHolder)shape.getPlaceholder();
return textHolder.getParagraphs();
} else {
return shape.getTextFrame().getParagraphs();
}
}
Now I try to upgrade my code to use the new API. But I do not know how to handle the case which Shape instance is not the AutoShape
private String getText(Shape shape) {
if (shape instanceof AutoShape) {
return ((AutoShape)shape).getTextFrame().getText();
} else {
How to handle this case?
}
}
private ParagraphCollection getParagraphs(Shape shape) {
if (shape instanceof AutoShape) {
return (ParagraphCollection) ((AutoShape)shape).getTextFrame().getParagraphs();
} else {
How to handle this case?
}
}
Hi Rui,
I have observed your requirements and also the old sample code. I like to share that you don’t really need else condition in case of new API. In Old API, there used to be TextHolders and both shapes holding text. In that case you needed if/else. Whereas in new API, all text is held in TextFrame that can be associated with AutoShape, table cells or SmartArts. So for this reason, you don’t really need to check else condition. However, you must check before getting paragraphs or text that if the text frame is Null.
Many Thanks,
You are right. The ICell, IAutoShape and ISmartartNodeget can directly get the TextFrame.
Other slide component such as Idatalabel, Icharttitle, Itrendline, Ioverridabletext can get the TextFrame as getTextFrameForOverriding(). And the Inotesslide can use getNotesTextFrame()For my case, I only need take care the IAutoShape .
Hi Rui,
Yes you are right that text frame is responsible for holding text where ever referred in presentation. In your case IAutoShape is suffice your needs. Please share, if I may help you further in this regard.
Many Thanks,