Line

Create Plain Line

To add a simple plain line to a selected slide of the presentation, please follow the steps below:

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its Index.
  • Add an AutoShape of Line type using AddAutoShape method exposed by Shapes object.
  • Write the modified presentation as a PPTX file.

In the example given below, we have added a line to the first slide of the presentation.

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String outPath = u"../out/AddPlainLineToSlide_out.pptx";
const String templatePath = u"../templates/AltText.pptx";
// Load the desired the presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// Access first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Add an autoshape of type line
SharedPtr<IAutoShape> shape = slide->get_Shapes()->AddAutoShape(ShapeType::Line, 50, 150, 300, 0);
//Write the PPTX to Disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Create Arrow Shaped Line

Aspose.Slides for C++ also allows developers to configure some properties of the line to make it look more appealing. Let’s try to configure few properties of a line to make it look like an arrow. Please follow the steps below to do so:

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its Index.
  • Add an AutoShape of Line type using AddAutoShape method exposed by Shapes object.
  • Set the Line Style to one of the styles as offered by Aspose.Slides for C++.
  • Set the Width of the line.
  • Set the Dash Style of the line to one of the styles offered by Aspose.Slides for C++.
  • Set the Arrow Head Style and Length of the start point of the line.
  • Set the Arrow Head Style and Length of the end point of the line.
  • Write the modified presentation as a PPTX file.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String outPath = u"../out/AddArrowShapedLineToSlide_out.pptx";
const String templatePath = u"../templates/AltText.pptx";
// Load the desired the presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// Access first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Add an autoshape of type line
SharedPtr<IAutoShape> shape = slide->get_Shapes()->AddAutoShape(ShapeType::Line, 50, 150, 300, 0);
// Apply some formatting on the line
shape->get_LineFormat()->set_Style(LineStyle::ThickBetweenThin);
shape->get_LineFormat()->set_Width(10);
shape->get_LineFormat()->set_DashStyle(LineDashStyle::DashDot);
shape->get_LineFormat()->set_BeginArrowheadLength(LineArrowheadLength::Short);
shape->get_LineFormat()->set_BeginArrowheadStyle(LineArrowheadStyle::Oval);
shape->get_LineFormat()->set_EndArrowheadLength(LineArrowheadLength::Long);
shape->get_LineFormat()->set_EndArrowheadStyle(LineArrowheadStyle::Triangle);
shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Maroon());
//Write the PPTX to Disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);