Free Support Forum - aspose.com

Help with drawing a flipped line (Java)

Can you help me with the code required to draw a line like the one in the attached file.


In PowerPoint itself, this line requires a horizontal flip but I don’t see a method to set that in Aspose.Slides.
Hi Shaun,

I have observed the requirements shared by you and like to share that at present the support for rotation of line in terms of float value is avalalble. The following sample code will help you in generating the desired line.

public static void addLine()throws Exception
{
//Instantiate PrseetationEx class that represents the PPTX
PresentationEx pres = new PresentationEx();

//Get the first slide
SlideEx sld = pres.getSlides().get_Item(0);

//Add autoshape of rectangle type
int idx = sld.getShapes().addAutoShape(ShapeTypeEx.Line, 242, 112, 199, 211);
ShapeEx shp = sld.getShapes().get_Item(idx);
shp.setRotation(90);
//Set the fill color of the rectangle shape
shp.getFillFormat().setFillType(FillTypeEx.Solid);
shp.getFillFormat().getSolidFillColor().setColor(Color.WHITE);
//set the color of the line of rectangle
shp.getLineFormat().getFillFormat().setFillType(FillTypeEx.Solid);
shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);

//Write the PPTX file to disk
pres.write("d:\\Aspose Data\\RectShpLn2.pptx");

}

I like to share that at present the Horizontal or vertical flip options is unavailable in Aspose.Slides. I have created an issue with ID SLIDESJAVA-33796 in our issue tracking system to provide the rotation options as mentioned. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved.

Many Thanks,

@Shaun_REM,

Using latest Aspose.Slides for Java 20.6, you can consider using the following example to create a flipped line on your end.

    public static void TestLineFlip()
    {
 
            Presentation TestPres = new Presentation();

            ISlide slide = TestPres.getSlides().get_Item(0);

            IAutoShape Line1 = slide.getShapes().addAutoShape(ShapeType.Line, 100f, 100f, 400f, 400f);

            Line1.getLineFormat().setEndArrowheadLength(LineArrowheadLength.Long);

            Line1.getLineFormat().setEndArrowheadStyle(LineArrowheadStyle.Triangle);

            Line1.getLineFormat().getFillFormat().setFillType(FillType.Solid);

            Line1.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.awt.Color.GRAY);

            Line1.getLineFormat().setWidth (5);

            IShapeFrame oldFrame = Line1.getFrame();
         
            //Adding a new shape by copying existing
            IAutoShape Line2 = (IAutoShape) slide.getShapes().addClone(Line1);

            Line2.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.awt.Color.RED);

            //Following code snippet will flip the shape horizontally
            Line2.setFrame (new ShapeFrame(oldFrame.getX(), oldFrame.getY(), oldFrame.getWidth(), oldFrame.getHeight(), NullableBool.True, oldFrame.getFlipV(), oldFrame.getRotation()));

            TestPres.save("C:\\Aspose Data\\Line.pptx",SaveFormat.Pptx);
    }

The issues you have found earlier (filed as SLIDESJAVA-33796) have been fixed in this update.