Shape Class |
Namespace: Aspose.Words.Drawing
The Shape type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | Shape |
Creates a new shape object.
|
Name | Description | |
---|---|---|
![]() ![]() | AllowOverlap |
Gets or sets a value that specifies whether this shape can overlap other shapes.
(Inherited from ShapeBase.) |
![]() ![]() | AlternativeText |
Defines alternative text to be displayed instead of a graphic.
(Inherited from ShapeBase.) |
![]() ![]() | AnchorLocked |
Specifies whether the shape's anchor is locked.
(Inherited from ShapeBase.) |
![]() ![]() | AspectRatioLocked |
Specifies whether the shape's aspect ratio is locked.
(Inherited from ShapeBase.) |
![]() ![]() | BehindText |
Specifies whether the shape is below or above text.
(Inherited from ShapeBase.) |
![]() ![]() | Bottom |
Gets the position of the bottom edge of the containing block of the shape.
(Inherited from ShapeBase.) |
![]() ![]() | Bounds |
Gets or sets the location and size of the containing block of the shape.
(Inherited from ShapeBase.) |
![]() ![]() | BoundsInPoints |
Gets the location and size of the containing block of the shape in points, relative to the anchor of the topmost shape.
(Inherited from ShapeBase.) |
![]() ![]() | BoundsWithEffects |
Gets final extent that this shape object has after applying drawing effects.
Value is measured in points.
(Inherited from ShapeBase.) |
![]() ![]() | CanHaveImage |
Returns true if the shape type allows the shape to have an image.
(Inherited from ShapeBase.) |
![]() ![]() | Chart |
Provides access to the chart properties if this shape has a Chart.
|
![]() ![]() | ChildNodes |
Gets all immediate child nodes of this node.
(Inherited from CompositeNode.) |
![]() ![]() | CoordOrigin |
The coordinates at the top-left corner of the containing block of this shape.
(Inherited from ShapeBase.) |
![]() ![]() | CoordSize |
The width and height of the coordinate space inside the containing block of this shape.
(Inherited from ShapeBase.) |
![]() ![]() | Count |
Gets the number of immediate children of this node.
(Inherited from CompositeNode.) |
![]() ![]() | DistanceBottom |
Returns or sets the distance (in points) between the document text and the bottom edge of the shape.
(Inherited from ShapeBase.) |
![]() ![]() | DistanceLeft |
Returns or sets the distance (in points) between the document text and the left edge of the shape.
(Inherited from ShapeBase.) |
![]() ![]() | DistanceRight |
Returns or sets the distance (in points) between the document text and the right edge of the shape.
(Inherited from ShapeBase.) |
![]() ![]() | DistanceTop |
Returns or sets the distance (in points) between the document text and the top edge of the shape.
(Inherited from ShapeBase.) |
![]() ![]() | Document |
Gets the document to which this node belongs.
(Inherited from Node.) |
![]() ![]() | ExtrusionEnabled |
Returns true if an extrusion effect is enabled.
|
![]() ![]() | Fill |
Defines a fill for a shape.
|
![]() ![]() | FillColor |
Defines the brush color that fills the closed path of the shape.
|
![]() ![]() | Filled |
Determines whether the closed path of the shape will be filled.
|
![]() ![]() | FirstChild |
Gets the first child of the node.
(Inherited from CompositeNode.) |
![]() ![]() | FirstParagraph |
Gets the first paragraph in the shape.
|
![]() ![]() | FlipOrientation |
Switches the orientation of a shape.
(Inherited from ShapeBase.) |
![]() ![]() | Font |
Provides access to the font formatting of this object.
(Inherited from ShapeBase.) |
![]() ![]() | HasChart |
Returns true if this Shape has a Chart.
|
![]() ![]() | HasChildNodes |
Returns true if this node has any child nodes.
(Inherited from CompositeNode.) |
![]() ![]() | HasImage |
Returns true if the shape has image bytes or links an image.
|
![]() ![]() | HasSmartArt |
Returns true if this Shape has a SmartArt object.
|
![]() ![]() | Height |
Gets or sets the height of the containing block of the shape.
(Inherited from ShapeBase.) |
![]() ![]() | HorizontalAlignment |
Specifies how the shape is positioned horizontally.
(Inherited from ShapeBase.) |
![]() ![]() | HorizontalRuleFormat |
Provides access to the properties of the horizontal rule shape.
For a shape that is not a horizontal rule, returns null.
|
![]() ![]() | HRef |
Gets or sets the full hyperlink address for a shape.
(Inherited from ShapeBase.) |
![]() ![]() | ImageData |
Provides access to the image of the shape.
Returns null if the shape cannot have an image.
|
![]() ![]() | IsComposite |
Returns true as this node can have child nodes.
(Inherited from CompositeNode.) |
![]() ![]() | IsDeleteRevision |
Returns true if this object was deleted in Microsoft Word while change tracking was enabled.
(Inherited from ShapeBase.) |
![]() ![]() | IsGroup |
Returns true if this is a group shape.
(Inherited from ShapeBase.) |
![]() ![]() | IsHorizontalRule |
Returns true if this shape is a horizontal rule.
(Inherited from ShapeBase.) |
![]() ![]() | IsImage |
Returns true if this shape is an image shape.
(Inherited from ShapeBase.) |
![]() ![]() | IsInline |
A quick way to determine if this shape is positioned inline with text.
(Inherited from ShapeBase.) |
![]() ![]() | IsInsertRevision |
Returns true if this object was inserted in Microsoft Word while change tracking was enabled.
(Inherited from ShapeBase.) |
![]() ![]() | IsLayoutInCell |
Gets or sets a flag indicating whether the shape is displayed inside a table or outside of it.
(Inherited from ShapeBase.) |
![]() ![]() | IsMoveFromRevision |
Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled.
(Inherited from ShapeBase.) |
![]() ![]() | IsMoveToRevision |
Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled.
(Inherited from ShapeBase.) |
![]() ![]() | IsSignatureLine |
Indicates that shape is a SignatureLine.
(Inherited from ShapeBase.) |
![]() ![]() | IsTopLevel |
Returns true if this shape is not a child of a group shape.
(Inherited from ShapeBase.) |
![]() ![]() | IsWordArt |
Returns true if this shape is a WordArt object.
(Inherited from ShapeBase.) |
![]() ![]() | LastChild |
Gets the last child of the node.
(Inherited from CompositeNode.) |
![]() ![]() | LastParagraph |
Gets the last paragraph in the shape.
|
![]() ![]() | Left |
Gets or sets the position of the left edge of the containing block of the shape.
(Inherited from ShapeBase.) |
![]() ![]() | MarkupLanguage |
Gets MarkupLanguage used for this graphic object.
(Inherited from ShapeBase.) |
![]() ![]() | Name |
Gets or sets the optional shape name.
(Inherited from ShapeBase.) |
![]() ![]() | NextSibling |
Gets the node immediately following this node.
(Inherited from Node.) |
![]() ![]() | NodeType |
Returns Shape.
(Overrides NodeNodeType.) |
![]() ![]() | OleFormat |
Provides access to the OLE data of a shape. For a shape that is not an OLE object or ActiveX control, returns null.
|
![]() ![]() | ParentNode |
Gets the immediate parent of this node.
(Inherited from Node.) |
![]() ![]() | ParentParagraph |
Returns the immediate parent paragraph.
(Inherited from ShapeBase.) |
![]() ![]() | PreviousSibling |
Gets the node immediately preceding this node.
(Inherited from Node.) |
![]() ![]() | Range |
Returns a Range object that represents the portion of a document that is contained in this node.
(Inherited from Node.) |
![]() ![]() | RelativeHorizontalPosition |
Specifies relative to what the shape is positioned horizontally.
(Inherited from ShapeBase.) |
![]() ![]() | RelativeVerticalPosition |
Specifies relative to what the shape is positioned vertically.
(Inherited from ShapeBase.) |
![]() ![]() | Right |
Gets the position of the right edge of the containing block of the shape.
(Inherited from ShapeBase.) |
![]() ![]() | Rotation |
Defines the angle (in degrees) that a shape is rotated.
Positive value corresponds to clockwise rotation angle.
(Inherited from ShapeBase.) |
![]() ![]() | ScreenTip |
Defines the text displayed when the mouse pointer moves over the shape.
(Inherited from ShapeBase.) |
![]() ![]() | ShadowEnabled |
Returns true if a shadow effect is enabled.
|
![]() ![]() | ShapeType |
Gets the shape type.
(Inherited from ShapeBase.) |
![]() ![]() | SignatureLine |
Gets SignatureLine object if the shape is a signature line. Returns null otherwise.
|
![]() ![]() | SizeInPoints |
Gets the size of the shape in points.
(Inherited from ShapeBase.) |
![]() ![]() | StoryType |
Returns Textbox.
|
![]() ![]() | Stroke |
Defines a stroke for a shape.
|
![]() ![]() | StrokeColor |
Defines the color of a stroke.
|
![]() ![]() | Stroked |
Defines whether the path will be stroked.
|
![]() ![]() | StrokeWeight |
Defines the brush thickness that strokes the path of a shape in points.
|
![]() ![]() | Target |
Gets or sets the target frame for the shape hyperlink.
(Inherited from ShapeBase.) |
![]() ![]() | TextBox |
Defines attributes that specify how text is displayed in a shape.
|
![]() ![]() | TextPath |
Defines the text of the text path (of a WordArt object).
|
![]() ![]() | Title |
Gets or sets the title (caption) of the current shape object.
(Inherited from ShapeBase.) |
![]() ![]() | Top |
Gets or sets the position of the top edge of the containing block of the shape.
(Inherited from ShapeBase.) |
![]() ![]() | VerticalAlignment |
Specifies how the shape is positioned vertically.
(Inherited from ShapeBase.) |
![]() ![]() | Width |
Gets or sets the width of the containing block of the shape.
(Inherited from ShapeBase.) |
![]() ![]() | WrapSide |
Specifies how the text is wrapped around the shape.
(Inherited from ShapeBase.) |
![]() ![]() | WrapType |
Defines whether the shape is inline or floating. For floating shapes defines the wrapping mode for text around the shape.
(Inherited from ShapeBase.) |
![]() ![]() | ZOrder |
Determines the display order of overlapping shapes.
(Inherited from ShapeBase.) |
Name | Description | |
---|---|---|
![]() ![]() | Accept |
Accepts a visitor.
(Overrides NodeAccept(DocumentVisitor).) |
![]() ![]() | AdjustWithEffects |
Adds to the source rectangle values of the effect extent and returns the final rectangle.
(Inherited from ShapeBase.) |
![]() ![]() | AppendChild |
Adds the specified node to the end of the list of child nodes for this node.
(Inherited from CompositeNode.) |
![]() ![]() | Clone | (Inherited from Node.) |
![]() | Equals | (Inherited from Object.) |
![]() ![]() | GetAncestor(Type) |
Gets the first ancestor of the specified object type.
(Inherited from Node.) |
![]() ![]() | GetAncestor(NodeType) |
Gets the first ancestor of the specified NodeType.
(Inherited from Node.) |
![]() ![]() | GetChild |
Returns an Nth child node that matches the specified type.
(Inherited from CompositeNode.) |
![]() ![]() | GetChildNodes |
Returns a live collection of child nodes that match the specified type.
(Inherited from CompositeNode.) |
![]() ![]() | GetEnumerator |
Provides support for the for each style iteration over the child nodes of this node.
(Inherited from CompositeNode.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() ![]() | GetShapeRenderer |
Creates and returns an object that can be used to render this shape into an image.
(Inherited from ShapeBase.) |
![]() ![]() | GetText |
Gets the text of this node and of all its children.
(Inherited from CompositeNode.) |
![]() | GetType | (Inherited from Object.) |
![]() ![]() | IndexOf |
Returns the index of the specified child node in the child node array.
(Inherited from CompositeNode.) |
![]() ![]() | InsertAfter |
Inserts the specified node immediately after the specified reference node.
(Inherited from CompositeNode.) |
![]() ![]() | InsertBefore |
Inserts the specified node immediately before the specified reference node.
(Inherited from CompositeNode.) |
![]() ![]() | LocalToParent |
Converts a value from the local coordinate space into the coordinate space of the parent shape.
(Inherited from ShapeBase.) |
![]() ![]() | NextPreOrder |
Gets next node according to the pre-order tree traversal algorithm.
(Inherited from Node.) |
![]() ![]() | PrependChild |
Adds the specified node to the beginning of the list of child nodes for this node.
(Inherited from CompositeNode.) |
![]() ![]() | PreviousPreOrder |
Gets the previous node according to the pre-order tree traversal algorithm.
(Inherited from Node.) |
![]() ![]() | Remove |
Removes itself from the parent.
(Inherited from Node.) |
![]() ![]() | RemoveAllChildren |
Removes all the child nodes of the current node.
(Inherited from CompositeNode.) |
![]() ![]() | RemoveChild |
Removes the specified child node.
(Inherited from CompositeNode.) |
![]() ![]() | RemoveSmartTags |
Removes all SmartTag descendant nodes of the current node.
(Inherited from CompositeNode.) |
![]() ![]() | SelectNodes |
Selects a list of nodes matching the XPath expression.
(Inherited from CompositeNode.) |
![]() ![]() | SelectSingleNode |
Selects the first Node that matches the XPath expression.
(Inherited from CompositeNode.) |
![]() | ToString | (Inherited from Object.) |
![]() ![]() | ToString(SaveFormat) |
Exports the content of the node into a string in the specified format.
(Inherited from Node.) |
![]() ![]() | ToString(SaveOptions) |
Exports the content of the node into a string using the specified save options.
(Inherited from Node.) |
Using the Shape class you can create or modify shapes in a Microsoft Word document.
An important property of a shape is its ShapeType. Shapes of different types can have different capabilities in a Word document. For example, only image and OLE shapes can have images inside them. Most of the shapes can have text, but not all.
Shapes that can have text, can contain Paragraph and Table nodes as children.
public void ExtractImagesToFiles() { Document doc = new Document(MyDir + "Images.docx"); NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true); int imageIndex = 0; foreach (Shape shape in shapes.OfType<Shape>()) { if (shape.HasImage) { string imageFileName = $"File.ExtractImagesToFiles.{imageIndex}{FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType)}"; shape.ImageData.Save(ArtifactsDir + imageFileName); imageIndex++; } } }
// This creates a builder and also an empty document inside the builder DocumentBuilder builder = new DocumentBuilder(); // By default, the image is inline Shape shape = builder.InsertImage(ImageDir + "Logo.jpg"); // Make the image float, put it behind text and center on the page shape.WrapType = WrapType.None; shape.BehindText = true; shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page; shape.HorizontalAlignment = HorizontalAlignment.Center; shape.RelativeVerticalPosition = RelativeVerticalPosition.Page; shape.VerticalAlignment = VerticalAlignment.Center; builder.Document.Save(ArtifactsDir + "Image.CreateFloatingPageCenter.doc");
// Here we get all shapes from the document node, but you can do this for any smaller // node too, for example delete shapes from a single section or a paragraph Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert 2 shapes builder.InsertShape(ShapeType.Rectangle, 400, 200); builder.InsertShape(ShapeType.Star, 300, 300); // Insert a GroupShape with an inner shape GroupShape group = new GroupShape(doc); group.Bounds = new RectangleF(100, 50, 200, 100); group.CoordOrigin = new Point(-1000, -500); Shape subShape = new Shape(doc, ShapeType.Cube); subShape.Width = 500; subShape.Height = 700; subShape.Left = 0; subShape.Top = 0; group.AppendChild(subShape); builder.InsertNode(group); Assert.AreEqual(3, doc.GetChildNodes(NodeType.Shape, true).Count); Assert.AreEqual(1, doc.GetChildNodes(NodeType.GroupShape, true).Count); // Delete all Shape nodes NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true); shapes.Clear(); // The GroupShape node is still present even though there are no sub Shapes Assert.AreEqual(1, doc.GetChildNodes(NodeType.GroupShape, true).Count); Assert.AreEqual(0, doc.GetChildNodes(NodeType.Shape, true).Count); // GroupShapes also have to be deleted manually NodeCollection groupShapes = doc.GetChildNodes(NodeType.GroupShape, true); groupShapes.Clear(); Assert.AreEqual(0, doc.GetChildNodes(NodeType.GroupShape, true).Count); Assert.AreEqual(0, doc.GetChildNodes(NodeType.Shape, true).Count);