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

Free Support Forum - aspose.com

How to copy background color from one shape to another shape

Hi Support Team,
How to copy styles like [ Background color, gradient ] from one shape to another shape?
How to add gradient background color to any of the shape?

Ex; I’ve tried getFillColor and setFillColor but not working, Color object doesn’t have values.

Please share sample code with example.

You can use Fill.oneColorGradient or Fill.twoColorGradient method to add gradient background to any shape. Please check the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shapeRec = builder.insertShape(ShapeType.RECTANGLE, 400, 200);
shapeRec.getFill().oneColorGradient(GradientStyle.FROM_CENTER, GradientVariant.VARIANT_1, 45);

Shape shapeTri = builder.insertShape(ShapeType.TRIANGLE, 200, 300);
shapeTri.getFill().twoColorGradient(Color.red, Color.white, GradientStyle.VERTICAL, GradientVariant.VARIANT_3);


Please check the API Reference page for more information.