# Add Line Shapes to Presentations in JavaScript

> Learn to manipulate line formatting in PowerPoint presentations with JavaScript and Aspose.Slides for Node.js. Discover properties, methods, and examples.

Source: https://docs.aspose.com/slides/nodejs-java/line/
Updated: 2026-08-05


## **Overview**

Aspose.Slides allows you to add line shapes to PowerPoint slides programmatically. This article shows how to create a simple line and how to customize a line so it appears as an arrow.

You will learn how to add a line shape to a slide, adjust its visual appearance, and save the updated presentation. The examples focus on practical line formatting settings such as style, width, dash pattern, arrowhead options, and fill color.

## **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](https://reference.aspose.com/slides/nodejs-java/aspose.slides/Presentation) class.
- Obtain the reference of a slide by using its Index.
- Add an AutoShape of Line type using [addAutoShape](https://reference.aspose.com/slides/nodejs-java/aspose.slides/ShapeCollection#addAutoShape-int-float-float-float-float-) method exposed by [ShapeCollection](https://reference.aspose.com/slides/nodejs-java/aspose.slides/ShapeCollection) 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.

```javascript
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");

// Instantiate PresentationEx class that represents the PPTX file
var pres = new aspose.slides.Presentation();
try {
    // Get the first slide
    var sld = pres.getSlides().get_Item(0);
    // Add an AutoShape of type line
    sld.getShapes().addAutoShape(aspose.slides.ShapeType.Line, 50, 150, 300, 0);
    // Write the PPTX to Disk
    pres.save("LineShape.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}
```

## **Create Arrow Shaped Line**

Aspose.Slides for Node.js via Java 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](https://reference.aspose.com/slides/nodejs-java/aspose.slides/Presentation) class.
- Obtain the reference of a slide by using its Index.
- Add an AutoShape of Line type using [addAutoShape](https://reference.aspose.com/slides/nodejs-java/aspose.slides/ShapeCollection#addAutoShape-int-float-float-float-float-) method exposed by [ShapeCollection](https://reference.aspose.com/slides/nodejs-java/aspose.slides/ShapeCollection) object.
- Set the [Line Style](https://reference.aspose.com/slides/nodejs-java/aspose.slides/LineStyle) to one of the styles as offered by Aspose.Slides for Node.js via Java.
- Set the Width of the line.
- Set the [Dash Style](https://reference.aspose.com/slides/nodejs-java/aspose.slides/LineDashStyle) of the line to one of the styles offered by Aspose.Slides for Node.js via Java.
- Set the [Arrow Head Style](https://reference.aspose.com/slides/nodejs-java/aspose.slides/LineArrowheadStyle) and [Length](https://reference.aspose.com/slides/nodejs-java/aspose.slides/LineArrowheadLength) of the start point of the line.
- Set the [Arrow Head Style](https://reference.aspose.com/slides/nodejs-java/aspose.slides/LineArrowheadStyle) and [Length](https://reference.aspose.com/slides/nodejs-java/aspose.slides/LineArrowheadLength) of the end point of the line.
- Write the modified presentation as a PPTX file.

```javascript
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");

// Instantiate PresentationEx class that represents the PPTX file
var pres = new aspose.slides.Presentation();
try {
    // Get the first slide
    var sld = pres.getSlides().get_Item(0);
    // Add an AutoShape of type line
    var shp = sld.getShapes().addAutoShape(aspose.slides.ShapeType.Line, 50, 150, 300, 0);
    // Apply some formatting on the line
    shp.getLineFormat().setStyle(java.newByte(aspose.slides.LineStyle.ThickBetweenThin));
    shp.getLineFormat().setWidth(10);
    shp.getLineFormat().setDashStyle(java.newByte(aspose.slides.LineDashStyle.DashDot));
    shp.getLineFormat().setBeginArrowheadLength(java.newByte(aspose.slides.LineArrowheadLength.Short));
    shp.getLineFormat().setBeginArrowheadStyle(java.newByte(aspose.slides.LineArrowheadStyle.Oval));
    shp.getLineFormat().setEndArrowheadLength(java.newByte(aspose.slides.LineArrowheadLength.Long));
    shp.getLineFormat().setEndArrowheadStyle(java.newByte(aspose.slides.LineArrowheadStyle.Triangle));
    shp.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
    // Maroon
    shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 128, 0, 0));
    // Write the PPTX to Disk
    pres.save("LineShape.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}
```

## **FAQ**

### Can I convert a regular line into a connector so it "snaps" to shapes?

No. A regular line (an [AutoShape](https://reference.aspose.com/slides/nodejs-java/aspose.slides/autoshape/) of type [Line](https://reference.aspose.com/slides/nodejs-java/aspose.slides/shapetype/)) does not automatically become a connector. To make it snap to shapes, use the dedicated [Connector](https://reference.aspose.com/slides/nodejs-java/aspose.slides/connector/) type and the [corresponding APIs](/slides/nodejs-java/connector/) for connections.

### What should I do if a line’s properties are inherited from the theme and it’s hard to determine the final values?

[Read the effective properties](/slides/nodejs-java/shape-effective-properties/) through the `ILineFormatEffectiveData`/`ILineFillFormatEffectiveData` classes—these already account for inheritance and theme styles.

### Can I lock a line against editing (moving, resizing)?

Yes. Shapes provide [lock objects](https://reference.aspose.com/slides/nodejs-java/aspose.slides/autoshape/getautoshapelock/) that let you disallow editing operations.

