Free Support Forum - aspose.com

Gradient path (1670)


#1

Hi,
I am trying to replace the portion from paragraph but keep the same gradient formating as the original portion. When I open the saved file they look different.Can you please check this out?
file: path.pptx.zip (21.0 KB)
picture: path.PNG (26.7 KB)

code:

String path = "path.pptx";

Presentation presentation = new Presentation(path);
ISlide slide = presentation.getSlides().get_Item(0);
AutoShape shape = (AutoShape) slide.getShapes().get_Item(0);
IParagraph paragraph = shape.getTextFrame().getParagraphs().get_Item(0);
IPortionCollection portions = paragraph.getPortions();
IPortion portion = portions.get_Item(0);

IGradientFormatEffectiveData gradientFormat = portion.createPortionFormatEffective().getFillFormat()
	.getGradientFormat();
byte gradientShape = gradientFormat.getGradientShape();
IGradientStopCollectionEffectiveData stops = gradientFormat.getGradientStops();

Portion newPortion = new Portion("Path");

IFillFormat fillFormat = newPortion.getPortionFormat().getFillFormat();

fillFormat.setFillType(FillType.Gradient);

IGradientFormat newPortionGradient = fillFormat.getGradientFormat();
newPortionGradient.setGradientShape(gradientShape);
newPortionGradient.getGradientStops().add(stops.get_Item(0).getPosition(), stops.get_Item(0).getColor());
newPortionGradient.getGradientStops().add(stops.get_Item(1).getPosition(), stops.get_Item(1).getColor());
newPortionGradient.getGradientStops().add(stops.get_Item(2).getPosition(), stops.get_Item(2).getColor());

portions.clear();
portions.add(newPortion);
presentation.save("saved.pptx", SaveFormat.Pptx);

Thanks,
Zeljko


#2

@Zeljko,

I have worked with presentation file shared by you and have been able to observe the issue specified. An issue with ID SLIDESJAVA-37009 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.


#3

The issues you have found earlier (filed as SLIDESJAVA-37009) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by mudassir.fayyaz


#4

Hi, I’m still having a problem with this, Can you please check this again?
I’m usiing latest aspose slides for java (19.2)
OpenJDK version “11.0.1”
Linux 4.4.0-96-generic x86_64


#5

@Zeljko,

I suggest you to please try using following sample code on your end and share with us if there is any further issue incurring on your end.

Presentation presentation = new Presentation("path.pptx");
ISlide slide = presentation.getSlides().get_Item(0);
AutoShape shape = (AutoShape) slide.getShapes().get_Item(0);
IParagraph paragraph = shape.getTextFrame().getParagraphs().get_Item(0);
IPortionCollection portions = paragraph.getPortions();
IPortion portion = portions.get_Item(0);

IGradientFormatEffectiveData gradientFormat = portion.createPortionFormatEffective().getFillFormat()
 .getGradientFormat();
byte gradientShape = gradientFormat.getGradientShape();
IGradientStopCollectionEffectiveData stops = gradientFormat.getGradientStops();

Portion newPortion = new Portion("Path");

IFillFormat fillFormat = newPortion.getPortionFormat().getFillFormat();

fillFormat.setFillType(FillType.Gradient);

IGradientFormat newPortionGradient = fillFormat.getGradientFormat();
newPortionGradient.setGradientShape(gradientShape);
newPortionGradient.setGradientDirection(gradientFormat.getGradientDirection());
newPortionGradient.getGradientStops().add(stops.get_Item(0).getPosition(), stops.get_Item(0).getColor());
newPortionGradient.getGradientStops().add(stops.get_Item(1).getPosition(), stops.get_Item(1).getColor());
newPortionGradient.getGradientStops().add(stops.get_Item(2).getPosition(), stops.get_Item(2).getColor());

portions.clear();
portions.add(newPortion);
presentation.save("saved.pptx", SaveFormat.Pptx);

#6

Thank you, that works. but GradientDirection cant be set from Microsoft powerpoint , seem redundant that i need to set it. Why do you think?
pic: direction.PNG (6.1 KB)


#7

@Zeljko

The gradient direction is required. I request you to please visit this API reference link for possible directions. Please check the following image for Gradient directions in PowerPoint.


#8

@mudassir.fayyaz I think if you set gradient fill with type Path than you wont be able to set direction?


#9

@Zeljko,

I suppose in that case it will not be required.


#10

@mudassir.fayyaz
If i don’t set direction it wont look the same and it should, that was my original problem.
I would not like to force direction for PATH gradientFill type in my code if it is unnecessary. Can i expect that you will fix this ?

Thanks,
Zeljko.


#11

@Zeljko,

The associated issue was logged for resolution of issue that when you try to replace the portion from paragraph but keep the same gradient formatting as the original portion. The sample code that I have shared in my previous reply was based on this. If there is still an issue then please share in the form of example, obtained and desired output. We will investigate that further on our end to help you out.


#12

If I wan’t to apply gradient fill format (type path) in MS PowerPoint to some other text, I am not able to set the direction (the option is disabled, not clickable) so it seems redundant if I need to set it through Aspose.Slides API.
direction.PNG (6.2 KB)


#13

@Zeljko,

When you use Path type gradient then direction become irrelevant in that case. You can also observe from the image you have shared that for Path type gradient the direction gets disabled.

Presentation presentation = new Presentation("path.pptx");
ISlide slide = presentation.getSlides().get_Item(0);
AutoShape shape = (AutoShape) slide.getShapes().get_Item(0);
IParagraph paragraph = shape.getTextFrame().getParagraphs().get_Item(0);
IPortionCollection portions = paragraph.getPortions();
IPortion portion = portions.get_Item(0);

IGradientFormatEffectiveData gradientFormat = portion.createPortionFormatEffective().getFillFormat()
 .getGradientFormat();
byte gradientShape = gradientFormat.getGradientShape();
IGradientStopCollectionEffectiveData stops = gradientFormat.getGradientStops();

Portion newPortion = new Portion("Path");

IFillFormat fillFormat = newPortion.getPortionFormat().getFillFormat();

fillFormat.setFillType(FillType.Gradient);

IGradientFormat newPortionGradient = fillFormat.getGradientFormat();
newPortionGradient.setGradientShape(gradientShape);

newPortionGradient.getGradientStops().add(stops.get_Item(0).getPosition(), stops.get_Item(0).getColor());
newPortionGradient.getGradientStops().add(stops.get_Item(1).getPosition(), stops.get_Item(1).getColor());
newPortionGradient.getGradientStops().add(stops.get_Item(2).getPosition(), stops.get_Item(2).getColor());

portions.clear();
portions.add(newPortion);
presentation.save("saved.pptx", SaveFormat.Pptx);