Free Support Forum - aspose.com

How to get size and color of text in slide

Hi Developer,

Can I ask a question,

we want to extract PPT text and show it in HTML. So we need get text size and color.
I have not found any method which can get text size. return value of portionFormat.getFontHeight() is NaN.
And when I tried to get color with portionFormat.getFillFormat().getSolidFillColor().getColor()
, it alaways give me rgb(0,0,0) even the color is blue.

Can you please help on this.

Thanks,
Stone

Hi Stone,


Thank you for inquiring Aspose.Slides.

I have observed your requirements and have worked over them. Please try using following sample code on your end to serve the purpose.

//Create an instance of Presentation class
Presentation pres = new Presentation();

//Get reference of a slide
ISlide slide = pres.getSlides().get_Item(0);
//Add an AutoShape of Rectangle type
IAutoShape ashp = slide.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 400, 300);
ashp.getFillFormat().setFillType(FillType.NoFill);
//Add TextFrame to the Rectangle
ashp.addTextFrame(“Aspose TextBox”);
IPortion port = ashp.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
IPortionFormat pf = port.getPortionFormat();
pf.setFontHeight(50);
pf.getFillFormat().setFillType(FillType.Solid);
pf.getFillFormat().getSolidFillColor().setColor(Color.green);

System.out.println(pf.getFillFormat().getSolidFillColor().getColor().toString());
System.out.println(pf.getFontHeight());

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,
PFA.

Where pf is IPortionFormat, We tried the following to get the color of Blue coloured Text. All of them are returning rbg(0,0,0)

pf.getFillFormat().getPatternFormat().getBackColor().getColor()
pf.getFillFormat().getPatternFormat().getForeColor().getColor()
pf.getFillFormat().getSolidFillColor().getColor()
pf.getHighlightColor().getColor()
pf.getFontHeight() is returning Nan.

Also, Please note that, We just need to read the PPT slides that we get as input and get the font size and color of the text. We should NOT set and get the colors and font height as you have given in the sample code above.

Please advise.

Hi Stone,


I have observed your comments and like to request you to please try using following sample code on your end to serve the purpose.

Presentation pres = new Presentation(“D://test.pptx”);
for (ISlide slide : pres.getSlides()) {
for (IShape shp : slide.getShapes())
if (shp.getPlaceholder()!= null) {
for (IParagraph paragraph : ((IAutoShape) shp)
.getTextFrame().getParagraphs()) {
for (IPortion portion : paragraph.getPortions()) {
if ((portion.getText().length()!=0)){
System.out.println("PTEXT: " + portion.getText());
System.out.println("FontHeight: "+ portion.createPortionFormatEffective().getFontHeight());
if (portion.getPortionFormat().getLatinFont() != null)
System.out.println("FontNameLatin: “+ portion.getPortionFormat().getLatinFont().getFontName());
System.out.println(” Fill Color: “+ portion.createPortionFormatEffective().getFillFormat().getSolidFillColor().toString());
System.out.println(” Highlight Color: “+ portion.createPortionFormatEffective().getHighlightColor().toString());
System.out.println(” Back Color: “+ portion.createPortionFormatEffective().getFillFormat().getPatternFormat().getBackColor().toString());
System.out.println(” Fore Color: "+ portion.createPortionFormatEffective().getFillFormat().getPatternFormat().getForeColor().toString());

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,

Hi Adnan,

Thanks!

portion.createPortionFormatEffective().getFontHeight()
and
portion.createPortionFormatEffective().getFillFormat().getSolidFillColor().getRed()

works.


Best Regards,
Stone

Hi Stone,


Thanks for your valuable feedback.We are glad to hear that, things have started working at your end.

Please feel free to contact us if we can be of any help to you.

Best Regards,