JavaScript에서 PowerPoint 도형 서식 지정
소개
PowerPoint에서 도형의 윤곽선, 채우기 및 효과를 조정하여 도형을 포맷합니다. Aspose.Slides for Node.js via Java를 사용하면 투명도, 회전 및 3D 포맷을 포함한 이러한 설정을 프로그래밍 방식으로 제어할 수 있습니다.

Aspose.Slides for Node.js via Java는 PowerPoint에서 사용할 수 있는 동일한 옵션을 사용하여 도형을 서식 지정할 수 있는 클래스와 메서드를 제공합니다.
선 서식
Use Shape.getLineFormat to control a shape’s outline. This example creates an unfilled rectangle with a blue, dashed outline. LineFormat.setStyle selects a thick-thin compound line, while LineFormat.setWidth sets its width to 7 points and LineFormat.setDashStyle selects the dash pattern.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 150, 75);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
shape.getLineFormat().setStyle(java.newByte(aspose.slides.LineStyle.ThickThin));
shape.getLineFormat().setWidth(7);
shape.getLineFormat().setDashStyle(java.newByte(aspose.slides.LineDashStyle.Dash));
shape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLUE"));
presentation.save("formatted_lines.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

사용자 지정 선 대시 패턴 설정
Use LineFormat.setCustomDashPattern when predefined line styles do not provide the dash lengths and gaps you need, for example for branded outlines or technical diagrams. Assigning a pattern automatically changes the line dash style to LineDashStyle.Custom.
Array entries alternate between dash and gap lengths, starting with a dash. Each value is a multiple of the line width: [4, 2] at a width of 3 points produces a 12-point dash followed by a 6-point gap. Use pairs of finite, nonnegative values to define complete dash-and-gap segments. The example uses positive values to keep every dash and gap visible.
This example creates five blue lines with the same length and flat caps. The first three compare patterns at a width of 3 points. The fourth repeats the first pattern at twice the width, doubling both the dash and gap lengths. The fifth switches from a custom pattern to a solid line.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
presentation.getSlideSize().setSize(600, 300, aspose.slides.SlideSizeScaleType.DoNotScale);
let slide = presentation.getSlides().get_Item(0);
let patterns = [
[4, 2],
[1, 2],
[6, 2, 1, 2],
[4, 2],
[4, 2]
];
for (let i = 0; i < patterns.length; i++) {
let line = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Line, 50, 50 + i * 50, 500, 0);
line.getLineFormat().setWidth(i == 3 ? 6 : 3);
line.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
line.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 0, 0, 139));
line.getLineFormat().setCapStyle(java.newByte(aspose.slides.LineCapStyle.Flat));
line.getLineFormat().setBeginArrowheadStyle(java.newByte(aspose.slides.LineArrowheadStyle.None));
line.getLineFormat().setEndArrowheadStyle(java.newByte(aspose.slides.LineArrowheadStyle.None));
let pattern = java.newArray("float", patterns[i]);
line.getLineFormat().setCustomDashPattern(pattern);
}
// 마지막 선을 실선 스타일로 반환합니다.
slide.getShapes().get_Item(4).getLineFormat().setDashStyle(java.newByte(aspose.slides.LineDashStyle.Solid));
presentation.save("custom_dash_patterns.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
To return to a predefined dashed style instead, pass LineDashStyle.Dash to LineFormat.setDashStyle. The selected style controls the line’s appearance.
PowerPoint에서 위에서 아래 순서대로의 결과: {4, 2}, 3 pt; {1, 2}, 3 pt; {6, 2, 1, 2}, 3 pt; {4, 2}, 6 pt; 그리고 Solid, 3 pt.

선 캡 설정
Use LineFormat.setCapStyle to set the ends of an open line. The LineCapStyle class provides three explicit cap styles:
Flat: The stroke stops at the endpoint.Round: A semicircular cap extends beyond the endpoint by half the line width.Square: A square cap extends beyond the endpoint by half the line width.
The class also includes NotDefined, which means that no cap style is explicitly assigned.
Caps are different from arrowheads, which add symbols to line ends, and joins, which control corners between line segments. This example disables arrowheads through LineFormat.setBeginArrowheadStyle and LineFormat.setEndArrowheadStyle so that only the cap shapes are compared.
The following example creates three otherwise identical horizontal lines, 20 points wide. From top to bottom, they use flat, round, and square caps. Their endpoints have the same horizontal coordinates; the round and square caps extend 10 points beyond each endpoint.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
presentation.getSlideSize().setSize(500, 240, aspose.slides.SlideSizeScaleType.DoNotScale);
let slide = presentation.getSlides().get_Item(0);
let capStyles = [aspose.slides.LineCapStyle.Flat, aspose.slides.LineCapStyle.Round, aspose.slides.LineCapStyle.Square];
for (let i = 0; i < capStyles.length; i++) {
let line = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Line, 100, 50 + i * 70, 300, 0);
line.getLineFormat().setWidth(20);
line.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
line.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 0, 0, 139));
line.getLineFormat().setDashStyle(java.newByte(aspose.slides.LineDashStyle.Solid));
line.getLineFormat().setCapStyle(java.newByte(capStyles[i]));
line.getLineFormat().setBeginArrowheadStyle(java.newByte(aspose.slides.LineArrowheadStyle.None));
line.getLineFormat().setEndArrowheadStyle(java.newByte(aspose.slides.LineArrowheadStyle.None));
}
presentation.save("line_caps.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
PowerPoint에서 위에서 아래 순서대로의 결과: Flat, Round, 그리고 Square.

도형 선에 스케치 효과 적용
A sketch effect makes a shape line look hand-drawn. Use Shape.getLineFormat to access the line settings, LineFormat.getSketchFormat to access the sketch settings, and SketchFormat.setSketchType to select a value from the LineSketchType class.
The following JavaScript code shows how to apply a LineSketchType.Curved effect, read the explicitly assigned value, and remove the effect with LineSketchType.None:
const aspose = { slides: require("aspose.slides.via.java") };
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 200, 100);
let sketchFormat = shape.getLineFormat().getSketchFormat();
sketchFormat.setSketchType(aspose.slides.LineSketchType.Curved);
let explicitSketchType = sketchFormat.getSketchType();
console.log("Explicit sketch type: " + explicitSketchType);
sketchFormat.setSketchType(aspose.slides.LineSketchType.None);
} finally {
presentation.dispose();
}
The value returned by SketchFormat.getSketchType represents the setting assigned directly to the shape. If the line formatting can be inherited from a theme, master slide, or layout slide, use LineFormat.getEffective, call getSketchFormat on the returned object, and then call its getSketchType method. The effective value reflects the formatting that is actually applied after inheritance is resolved. This example requires an existing presentation with at least one shape on its first slide and prints both values:
const aspose = { slides: require("aspose.slides.via.java") };
let presentation = new aspose.slides.Presentation("presentation.pptx");
try {
let shape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
let lineFormat = shape.getLineFormat();
let explicitSketchType = lineFormat.getSketchFormat().getSketchType();
let effectiveLineFormat = lineFormat.getEffective();
let effectiveSketchType = effectiveLineFormat.getSketchFormat().getSketchType();
console.log("Explicit sketch type: " + explicitSketchType);
console.log("Effective sketch type: " + effectiveSketchType);
} finally {
presentation.dispose();
}
조인 스타일 서식
Here are the three join type options:
- Round
- Miter
- Bevel
The join style controls how two outline segments meet at a corner. Use Round for rounded corners, Miter for sharp corners, or Bevel for flattened corners.

This example creates three black rectangles with blue outlines 15 points wide. It uses LineFormat.setJoinStyle to apply the miter, bevel, and round values of LineJoinStyle, respectively, to compare how the corners are drawn.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let miterShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 20, 20, 150, 75);
let bevelShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 210, 20, 150, 75);
let roundShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 20, 135, 150, 75);
miterShape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
miterShape.getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
bevelShape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
bevelShape.getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
roundShape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
roundShape.getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
miterShape.getLineFormat().setWidth(15);
bevelShape.getLineFormat().setWidth(15);
roundShape.getLineFormat().setWidth(15);
miterShape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
miterShape.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLUE"));
bevelShape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
bevelShape.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLUE"));
roundShape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
roundShape.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLUE"));
miterShape.getLineFormat().setJoinStyle(java.newByte(aspose.slides.LineJoinStyle.Miter));
bevelShape.getLineFormat().setJoinStyle(java.newByte(aspose.slides.LineJoinStyle.Bevel));
roundShape.getLineFormat().setJoinStyle(java.newByte(aspose.slides.LineJoinStyle.Round));
miterShape.getTextFrame().setText("Miter Join Style");
bevelShape.getTextFrame().setText("Bevel Join Style");
roundShape.getTextFrame().setText("Round Join Style");
presentation.save("join_styles.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
날카로운 각도에서 마이터 조인 제한
Use LineFormat.setMiterLimit with LineFormat.setJoinStyle set to LineJoinStyle.Miter to limit how far a sharp corner can extend.
The limit is a ratio of the distance between the inner and outer corners of the join to the line width. For example, a value of 8 permits a miter length of up to eight times the line width; it is not a measurement in points. If the corner would exceed the limit, PowerPoint uses a beveled join at that corner. A larger limit allows sharper points. The setting affects miter joins only, and changing it has no visible effect when the corner remains within both limits.
This example creates two identical, unfilled triangles with outlines 20 points wide. The left triangle uses a limit of 2, and the right uses 8. Each triangle is 80 points wide and 160 points high, giving its top corner a miter-length-to-line-width ratio of approximately 4.12. Consequently, PowerPoint bevels the left apex and preserves the right apex.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
presentation.getSlideSize().setSize(500, 320, aspose.slides.SlideSizeScaleType.DoNotScale);
let slide = presentation.getSlides().get_Item(0);
let miterLimits = [2, 8];
for (let i = 0; i < miterLimits.length; i++) {
let triangle = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Triangle, 90 + i * 240, 110, 80, 160);
triangle.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
triangle.getLineFormat().setWidth(20);
triangle.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
triangle.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 0, 0, 139));
triangle.getLineFormat().setJoinStyle(java.newByte(aspose.slides.LineJoinStyle.Miter));
triangle.getLineFormat().setMiterLimit(java.newFloat(miterLimits[i]));
}
presentation.save("miter_limits.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
PowerPoint에서 결과: 왼쪽에 Miter limit 2, 오른쪽에 miter limit 8.

그라디언트 채우기
A gradient fill blends colors across a shape. This example fills an ellipse with a linear gradient at a 45-degree angle from red to purple using FillFormat.getGradientFormat. The GradientStopCollection.addPresetColor method places the color stops at 0 and 1, the beginning and end of the gradient. Clearing the existing stops ensures that only these two colors are used.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Ellipse, 50, 50, 150, 75);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Gradient));
shape.getFillFormat().getGradientFormat().setGradientShape(java.newByte(aspose.slides.GradientShape.Linear));
shape.getFillFormat().getGradientFormat().setLinearGradientAngle(45);
shape.getFillFormat().getGradientFormat().getGradientStops().clear();
shape.getFillFormat().getGradientFormat().getGradientStops().addPresetColor(1.0, aspose.slides.PresetColor.Purple);
shape.getFillFormat().getGradientFormat().getGradientStops().addPresetColor(0.0, aspose.slides.PresetColor.Red);
presentation.save("gradient_fill.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

If a gradient looks different in an exported image than it does in PowerPoint, see Choose a Gradient Rendering Style. You can select a rendering style without changing the gradient fill stored in the presentation.
선형 그라디언트 각도 설정
Use GradientFormat.setLinearGradientAngle to control the orientation of a GradientShape.Linear fill. The angle is measured in degrees and increases clockwise: 0 runs from left to right, 90 from top to bottom, 180 from right to left, and 270 from bottom to top. Fractional angles are supported. Finite angles outside [0, 360) are normalized to one revolution; for example, -45 becomes 315 and 360 becomes 0.
This example creates six rectangles with identical red, green, and blue stops at positions 0, 0.5, and 1. Scaling is disabled so that the angle can be compared independently of the rectangles' proportions. The angles, from left to right, are 0, 45, and 90 in the first row, and 135, 180, and 270 in the second row.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
presentation.getSlideSize().setSize(720, 400, aspose.slides.SlideSizeScaleType.DoNotScale);
let slide = presentation.getSlides().get_Item(0);
let angles = [0, 45, 90, 135, 180, 270];
for (let i = 0; i < angles.length; i++) {
let x = 30 + (i % 3) * 230;
let y = 30 + Math.floor(i / 3) * 190;
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, x, y, 200, 150);
shape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Gradient));
let gradient = shape.getFillFormat().getGradientFormat();
gradient.setGradientShape(java.newByte(aspose.slides.GradientShape.Linear));
gradient.getGradientStops().clear();
gradient.getGradientStops().add(0, java.getStaticFieldValue("java.awt.Color", "RED"));
gradient.getGradientStops().add(java.newFloat(0.5), java.getStaticFieldValue("java.awt.Color", "GREEN"));
gradient.getGradientStops().add(1, java.getStaticFieldValue("java.awt.Color", "BLUE"));
gradient.setLinearGradientScaled(java.newByte(aspose.slides.NullableBool.False));
gradient.setLinearGradientAngle(angles[i]);
}
presentation.save("linear_gradient_angles.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
PowerPoint에서 결과:

도형에 맞춰 선형 그라디언트 스케일링
GradientFormat.setLinearGradientScaled accepts a NullableBool value. Set it explicitly to False to keep the geometric gradient angle as the shape’s proportions change, or to True to scale the gradient with the shape’s width and height. With scaling enabled, the visible angle can differ from the assigned angle on a non-square shape.
The following example uses a 45-degree angle and the same color stops as the angle comparison. The left column uses False; the right column uses True. Each column contains a wide rectangle above a tall rectangle. Both start with the same wide dimensions; changing the second rectangle’s width and height demonstrates how the fill responds to resizing without changing its gradient settings.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
presentation.getSlideSize().setSize(720, 460, aspose.slides.SlideSizeScaleType.DoNotScale);
let slide = presentation.getSlides().get_Item(0);
let scalingOptions = [aspose.slides.NullableBool.False, aspose.slides.NullableBool.True];
for (let column = 0; column < scalingOptions.length; column++) {
for (let row = 0; row < 2; row++) {
let x = 30 + column * 360;
let y = row == 0 ? 30 : 150;
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, x, y, 300, 90);
shape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Gradient));
let gradient = shape.getFillFormat().getGradientFormat();
gradient.setGradientShape(java.newByte(aspose.slides.GradientShape.Linear));
gradient.getGradientStops().clear();
gradient.getGradientStops().add(0, java.getStaticFieldValue("java.awt.Color", "RED"));
gradient.getGradientStops().add(java.newFloat(0.5), java.getStaticFieldValue("java.awt.Color", "GREEN"));
gradient.getGradientStops().add(1, java.getStaticFieldValue("java.awt.Color", "BLUE"));
gradient.setLinearGradientAngle(45);
gradient.setLinearGradientScaled(java.newByte(scalingOptions[column]));
if (row == 1) {
shape.setWidth(90);
shape.setHeight(280);
}
}
}
presentation.save("linear_gradient_scaling.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
PowerPoint에서 결과, 왼쪽은 스케일링 비활성화, 오른쪽은 스케일링 활성화:

With scaling disabled, the diagonal color bands keep the same orientation in both rectangles. With scaling enabled, the bands stretch with the shape’s proportions. This helps reproduce a template’s gradient when adapting a shape to a different size. On a square, enabling scaling does not change the appearance of this 45-degree gradient.
Both the angle and scaling settings apply to linear gradients. They do not control GradientShape.Radial or GradientShape.Rectangle fills.
각도와 그라디언트 방향 결합
GradientFormat.setGradientDirection selects a gradient style from the GradientDirection class; it is not a substitute for a numeric angle. For a linear gradient, the corner styles can change the area over which the colors are distributed without changing the angle assigned through setLinearGradientAngle. Keep the direction unchanged when comparing angles or scaling.
The following example applies the same settings in opposite orders. The two rectangles have the same appearance: assigning the direction before or after the angle does not change the result.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
for (let i = 0; i < 2; i++) {
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 30, 30 + i * 140, 320, 100);
shape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Gradient));
let gradient = shape.getFillFormat().getGradientFormat();
gradient.setGradientShape(java.newByte(aspose.slides.GradientShape.Linear));
gradient.getGradientStops().clear();
gradient.getGradientStops().add(0, java.getStaticFieldValue("java.awt.Color", "RED"));
gradient.getGradientStops().add(java.newFloat(0.5), java.getStaticFieldValue("java.awt.Color", "GREEN"));
gradient.getGradientStops().add(1, java.getStaticFieldValue("java.awt.Color", "BLUE"));
gradient.setLinearGradientScaled(java.newByte(aspose.slides.NullableBool.True));
if (i == 0) {
gradient.setGradientDirection(aspose.slides.GradientDirection.FromCorner1);
gradient.setLinearGradientAngle(30);
} else {
gradient.setLinearGradientAngle(30);
gradient.setGradientDirection(aspose.slides.GradientDirection.FromCorner1);
}
}
presentation.save("linear_gradient_direction.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
패턴 채우기
A pattern fill applies a two-color design, such as dots, stripes, or checks. This example uses PatternFormat.setPatternStyle to select a trellis pattern. PatternFormat.getBackColor supplies the light gray background, and PatternFormat.getForeColor supplies the yellow pattern color.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 150, 75);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Pattern));
shape.getFillFormat().getPatternFormat().setPatternStyle(java.newByte(aspose.slides.PatternStyle.Trellis));
shape.getFillFormat().getPatternFormat().getBackColor().setColor(java.getStaticFieldValue("java.awt.Color", "LIGHT_GRAY"));
shape.getFillFormat().getPatternFormat().getForeColor().setColor(java.getStaticFieldValue("java.awt.Color", "YELLOW"));
presentation.save("pattern_fill.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

그림 채우기
A picture fill uses an image inside a shape. This example requires a local image and uses Images.fromFile to load it into the presentation’s image collection. Setting PictureFillFormat.setPictureFillMode to the tiled mode repeats the image within the rectangle. The source image used here is shown below:

const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 255, 130);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Picture));
shape.getFillFormat().getPictureFillFormat().setPictureFillMode(aspose.slides.PictureFillMode.Tile);
let image = aspose.slides.Images.fromFile("lotus.png");
let picture;
try {
picture = presentation.getImages().addImage(image);
} finally {
image.dispose();
}
shape.getFillFormat().getPictureFillFormat().getPicture().setImage(picture);
presentation.save("picture_fill.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

텍스처로 타일 그림 설정
If you want to set a tiled picture as a texture and customize the tiling behavior, you can use the following methods of the PictureFillFormat class:
- setPictureFillMode: Sets the picture fill mode—either
TileorStretch. - setTileAlignment: Specifies the alignment of the tiles within the shape.
- setTileFlip: Controls whether the tile is flipped horizontally, vertically, or both.
- setTileOffsetX: Sets the horizontal offset of the tile (in points) from the shape’s origin.
- setTileOffsetY: Sets the vertical offset of the tile (in points) from the shape’s origin.
- setTileScaleX: Defines the horizontal scale of the tile as a percentage.
- setTileScaleY: Defines the vertical scale of the tile as a percentage.
This example requires a local image and configures PictureFillFormat to repeat it at 50% of its original size. Offsets of −32 points shift the tiles horizontally and vertically; bottom-right alignment and flipping in both directions determine how the repeated texture is arranged.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
let firstSlide = presentation.getSlides().get_Item(0);
let shape = firstSlide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 190, 95);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Picture));
let sourceImage = aspose.slides.Images.fromFile("lotus.png");
let presentationImage;
try {
presentationImage = presentation.getImages().addImage(sourceImage);
} finally {
sourceImage.dispose();
}
let pictureFillFormat = shape.getFillFormat().getPictureFillFormat();
pictureFillFormat.getPicture().setImage(presentationImage);
pictureFillFormat.setPictureFillMode(aspose.slides.PictureFillMode.Tile);
pictureFillFormat.setTileOffsetX(-32);
pictureFillFormat.setTileOffsetY(-32);
pictureFillFormat.setTileScaleX(50);
pictureFillFormat.setTileScaleY(50);
pictureFillFormat.setTileAlignment(java.newByte(aspose.slides.RectangleAlignment.BottomRight));
pictureFillFormat.setTileFlip(aspose.slides.TileFlip.FlipBoth);
presentation.save("tile.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

단색 채우기
A solid fill gives a shape a single, uniform color. This example uses FillFormat.setFillType to select the solid fill mode and assigns yellow through FillFormat.getSolidFillColor, then saves the rectangle in a presentation.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 150, 75);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
shape.getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "YELLOW"));
presentation.save("solid_color_fill.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

테마 참조를 유지하면서 색상 복사
Use ColorFormat.copyFrom to copy a color definition, including its color type, theme reference, and transformations. This is useful when transferring a fill color between shapes that should continue to follow the presentation theme. The method copies only the color: it does not copy the fill type, outline, or other shape formatting. Set the destination’s fill type explicitly with FillFormat.setFillType.
This example creates three rectangles, from left to right: the source, a theme-aware copy, and a fixed RGB copy. The source uses ColorFormat.setSchemeColor to reference the first accent color and adds a tint through ColorOperationCollection.add. The RGB copy uses the source’s effective fill color so all three initially look identical. Calling ColorFormat.setColor sets a fixed RGB value and clears any existing color transformations.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
presentation.getSlideSize().setSize(660, 220, aspose.slides.SlideSizeScaleType.DoNotScale);
let slide = presentation.getSlides().get_Item(0);
presentation.getMasterTheme().getColorScheme().getAccent1().setColor(java.newInstanceSync("java.awt.Color", 65, 105, 225));
let source = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 30, 40, 180, 140);
let themeCopy = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 240, 40, 180, 140);
let rgbCopy = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 450, 40, 180, 140);
for (let shape of [source, themeCopy, rgbCopy]) {
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
shape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
}
let sourceColor = source.getFillFormat().getSolidFillColor();
sourceColor.setSchemeColor(aspose.slides.SchemeColor.Accent1);
sourceColor.getColorTransform().add(aspose.slides.ColorTransformOperation.Tint, java.newFloat(0.75));
themeCopy.getFillFormat().getSolidFillColor().copyFrom(sourceColor);
rgbCopy.getFillFormat().getSolidFillColor().setColor(source.getFillFormat().getEffective().getSolidFillColor());
let before = slide.getImage(1, 1);
try {
before.save("color-copy-before.png", aspose.slides.ImageFormat.Png);
} finally {
before.dispose();
}
// 테마 참조는 새로운 강조 색을 따르고; 고정된 RGB 값은 따르지 않습니다.
presentation.getMasterTheme().getColorScheme().getAccent1().setColor(java.newInstanceSync("java.awt.Color", 255, 69, 0));
let after = slide.getImage(1, 1);
try {
after.save("color-copy-after.png", aspose.slides.ImageFormat.Png);
} finally {
after.dispose();
}
presentation.save("copied_colors.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
테마 변경 전, 세 개의 채우기가 모두 일치:

테마 변경 후, 소스와 테마 인식 복제는 새로운 강조 색을 따르고 색조를 유지합니다. 고정 RGB 복제는 파란색 그대로 유지:

The copied definition is independent of the source. Subsequently changing the source’s theme reference, assigning another color, or adding or removing its transformations does not change the destination. A theme change still affects both shapes because each independently refers to the same theme color.
Saving and reopening the PPTX preserves the copied color’s type returned by ColorFormat.getColorType, theme reference, and transformation collection returned by ColorFormat.getColorTransform; it does not flatten the definition to RGB.
When copying between different theme contexts, such as presentations with different accent palettes, the copied reference resolves against the destination’s theme. The same reference and transformations can therefore produce a different visible color. See Presentation Theme for more about configuring theme colors.
슬라이드 배경을 도형 채우기로 사용
Use AutoShape.setUseBackgroundFill when a shape should match the slide background, for example in a presentation template. Set the fill type with FillFormat.setFillType to FillType.NotDefined first to remove any explicit fill. With this combination, the shape uses the slide background instead of its style fill. Enabling the flag alone does not remove an existing explicit fill.
This differs from FillType.NoFill: background fill covers objects behind the shape with the corresponding area of the slide background, while no fill leaves those objects visible. A gradient remains aligned with the slide rather than restarting inside each shape.
The following example creates a master background inherited by the slide and places a magenta band behind three rectangles. The left rectangle uses the background, the middle rectangle has no fill, and the right rectangle switches from background fill to an explicit orange fill.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
presentation.getSlideSize().setSize(720, 400, aspose.slides.SlideSizeScaleType.DoNotScale);
let slide = presentation.getSlides().get_Item(0);
// 마스터로부터 그라디언트를 상속합니다.
slide.getBackground().setType(java.newByte(aspose.slides.BackgroundType.NotDefined));
slide.getLayoutSlide().getBackground().setType(java.newByte(aspose.slides.BackgroundType.NotDefined));
let background = slide.getLayoutSlide().getMasterSlide().getBackground();
background.setType(java.newByte(aspose.slides.BackgroundType.OwnBackground));
background.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Gradient));
let gradient = background.getFillFormat().getGradientFormat();
gradient.setGradientShape(java.newByte(aspose.slides.GradientShape.Linear));
gradient.setLinearGradientAngle(0);
gradient.getGradientStops().clear();
gradient.getGradientStops().add(0, java.newInstanceSync("java.awt.Color", 0, 0, 139));
gradient.getGradientStops().add(1, java.newInstanceSync("java.awt.Color", 135, 206, 250));
// 이 객체를 먼저 추가하여 사각형 뒤에 표시되도록 합니다.
let band = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 25, 150, 670, 100);
band.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
band.getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "MAGENTA"));
band.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
let backgroundShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 100, 160, 200);
backgroundShape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NotDefined));
backgroundShape.setUseBackgroundFill(true);
let noFillShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 280, 100, 160, 200);
noFillShape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
let explicitShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 510, 100, 160, 200);
explicitShape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NotDefined));
explicitShape.setUseBackgroundFill(true);
// 명시적 채우기를 적용하기 전에 배경 채우기를 비활성화합니다.
explicitShape.setUseBackgroundFill(false);
explicitShape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
explicitShape.getFillFormat().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 255, 165, 0));
presentation.save("background_fill.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과, 왼쪽부터 오른쪽 순서: 배경 채우기, 채우기 없음, 명시적 채우기. 마젠타 밴드는 왼쪽과 오른쪽 사각형에 가려지지만 가운데 사각형을 통해서는 보입니다.

The same behavior applies to a background defined directly on the slide or inherited from a layout. The shape uses the slide’s resolved background; the example leaves both the slide and layout backgrounds undefined so the master supplies it.
투명도 설정
For a solid fill, the color’s alpha component controls opacity: 0 is fully transparent and 255 is fully opaque. This example uses an alpha value of 128 for a yellow rectangle, making it approximately 50% transparent so the rectangle underneath remains visible. The color is assigned through FillFormat.getSolidFillColor.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let solidShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 150, 75);
let transparentShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 80, 80, 150, 75);
transparentShape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
transparentShape.getFillFormat().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 255, 255, 0, 128));
presentation.save("shape_transparency.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

도형 회전
Use Shape.setRotation to rotate a shape in the slide plane. The angle is measured in degrees; this example rotates a rectangle 5 degrees clockwise and saves the presentation.
const aspose = { slides: require("aspose.slides.via.java") };
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 150, 75);
shape.setRotation(5);
presentation.save("shape_rotation.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

3D 베벨 효과 추가
Use Shape.getThreeDFormat to give a shape depth and beveled edges. This example creates a green ellipse with an orange outline, uses ThreeDFormat.setDepth to set the depth to 4 points, and applies a circular top bevel with a width and height of 6 points through ThreeDFormat.getBevelTop. A front-facing orthographic camera and three-point lighting make the bevel visible.
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Ellipse, 50, 50, 100, 100);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
shape.getFillFormat().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 0, 128, 0));
shape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 255, 165, 0));
shape.getLineFormat().setWidth(2.0);
shape.getThreeDFormat().setDepth(4);
shape.getThreeDFormat().getBevelTop().setBevelType(aspose.slides.BevelPresetType.Circle);
shape.getThreeDFormat().getBevelTop().setHeight(6);
shape.getThreeDFormat().getBevelTop().setWidth(6);
shape.getThreeDFormat().getCamera().setCameraType(aspose.slides.CameraPresetType.OrthographicFront);
shape.getThreeDFormat().getLightRig().setLightType(aspose.slides.LightRigPresetType.ThreePt);
shape.getThreeDFormat().getLightRig().setDirection(aspose.slides.LightingDirection.Top);
presentation.save("3D_bevel_effect.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

3D 회전 효과 추가
A shape’s 3D view is controlled by its camera settings. This example uses Camera.setRotation with latitude, longitude, and revolution angles of 40, 35, and 20 degrees, respectively. It selects an isometric camera through Camera.setCameraType and balanced lighting through LightRig.setLightType, then saves the formatted rectangle.
const aspose = { slides: require("aspose.slides.via.java") };
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let autoShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 150, 75);
autoShape.getTextFrame().setText("Hello, Aspose!");
autoShape.getThreeDFormat().getCamera().setCameraType(aspose.slides.CameraPresetType.IsometricLeftUp);
autoShape.getThreeDFormat().getCamera().setRotation(40, 35, 20);
autoShape.getThreeDFormat().getLightRig().setLightType(aspose.slides.LightRigPresetType.Balanced);
presentation.save("3D_rotation_effect.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

도형의 흑백 렌더링 제어
The Shape.setBlackWhiteMode method specifies how an individual shape is rendered when a presentation is viewed or processed in black-and-white mode. It does not enable black-and-white display by itself, and it does not change the shape’s fill, line, or other formatting in normal color mode.
Use a value from the BlackWhiteMode class to select the desired behavior. For example, Automatic lets the rendering application choose the conversion, Gray and LightGray use gray coloring, BlackWhite uses only black and white, Black and White force a single color, Color preserves normal coloring, and Hidden omits the shape in black-and-white mode. NotDefined means that no shape-level mode is assigned.
This example creates an orange rectangle and uses Shape.setBlackWhiteMode to select gray coloring. The saved shape retains its orange fill for normal color display and requests gray coloring from applications that honor black-and-white display settings:
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 200, 100);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
shape.getFillFormat().getSolidFillColor().setColor(java.newInstanceSync("java.awt.Color", 255, 165, 0));
shape.setBlackWhiteMode(java.newByte(aspose.slides.BlackWhiteMode.Gray));
presentation.save("shape_black_white_mode.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
일반 색상 모드에서는 사각형이 주황색 채우기를 유지합니다. 흑백 표시 워크플로에서는 Gray 모드가 적용되어 회색으로 표시됩니다. 이를 통해 전체 색상 슬라이드를 보존하면서 인쇄, 미리 보기 또는 흑백 표시 설정을 준수하는 워크플로에 별도 외관을 정의할 수 있습니다.
서식 재설정
Use Slide.reset to restore the position, size, and formatting of slide placeholders from their corresponding layout placeholders. This example requires an existing presentation with layout-linked placeholders and resets every slide before saving. Shapes without corresponding layout placeholders are not reset.
const aspose = { slides: require("aspose.slides.via.java") };
let presentation = new aspose.slides.Presentation("sample.pptx");
try {
for (let i = 0; i < presentation.getSlides().size(); i++) {
let slide = presentation.getSlides().get_Item(i);
slide.reset();
}
presentation.save("reset_formatting.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
FAQ
Does shape formatting affect the final presentation file size?
Colors, line styles, and effect settings generally add little data compared with embedded images and media. Picture fills can increase the file size because their images are stored in the presentation.
How can I detect shapes on a slide that share identical formatting so I can group them?
Compare each shape’s key formatting properties—fill, line, and effect settings. If all corresponding values match, treat their styles as identical and logically group those shapes, which simplifies later style management.
Can I save a set of custom shape styles to a separate file for reuse in other presentations?
Yes. Store sample shapes with the desired styles in a template slide deck or a .POTX template file. When creating a new presentation, open the template, clone the styled shapes you need, and reapply their formatting wherever required.