We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Shape API

Can I do this?

This is only what I want to do.
but I couldn’t find some feature

only.docx (18.5 KB)

@muyoungko Sure you can achieve this using Aspose.Words. For example see the following code:

Document doc = new Document();

// Create round shape
Shape roundShape = new Shape(doc, ShapeType.Ellipse);
roundShape.StrokeColor = Color.Orange;
roundShape.StrokeWeight = 2;
roundShape.Width = 20;
roundShape.Height = 20;
roundShape.TextBox.InternalMarginTop = 0;
roundShape.TextBox.InternalMarginBottom = 0;
roundShape.TextBox.InternalMarginLeft = 0;
roundShape.TextBox.InternalMarginRight = 0;

// Put content into the round shape.
Paragraph shapeContent = new Paragraph(doc);
shapeContent.ParagraphBreakFont.Size = 8;
Run shapeContentText = new Run(doc, "123");
shapeContentText.Font.Size= 8;
shapeContent.AppendChild(shapeContentText);
roundShape.AppendChild(shapeContent);

// Create an arrow shape
Shape arrowShape = new Shape(doc, ShapeType.Line);
arrowShape.Width = 20;
arrowShape.Height = 1;
arrowShape.Stroke.EndArrowType = ArrowType.Open;
arrowShape.StrokeColor = Color.Orange;
arrowShape.StrokeWeight = 2;
arrowShape.Rotation = -10;

// Adjustposition of the shapes.
roundShape.WrapType = WrapType.None;
roundShape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
roundShape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
roundShape.Left = 100;
roundShape.Top = 100;

arrowShape.WrapType = WrapType.None;
arrowShape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
arrowShape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
arrowShape.Left = 120;
arrowShape.Top = 105;

// Insert the shapes into the document.
doc.FirstSection.Body.FirstParagraph.AppendChild(roundShape);
doc.FirstSection.Body.FirstParagraph.AppendChild(arrowShape);

doc.Save(@"C:\Temp\out.docx");

Here is the output document produced by this code: out.docx (7.2 KB)

You can also create such shapes in MS Word and access and change them using Aspose.Words, for example if only text and position should be changed.

1 Like

Very thanks for quick support, I will try and back

1 Like

Here is my code and out.docx

Circles are not well drawn.

Can you check it?

My gradle is this, and environment is mac and IntelliJ
implementation ‘com.aspose:aspose-words:22.9:jdk17’
Microsoft Word for Mac Version 16.69.1

out.docx (17.4 KB)
image.png (27.8 KB)

Document doc = new Document();

// Create round shape
Shape roundShape = new Shape(doc, ShapeType.ELLIPSE);
roundShape.setStrokeColor(Color.ORANGE);
roundShape.setStrokeWeight(2);
roundShape.setWidth(20);
roundShape.setWidth(20);
roundShape.getTextBox().setInternalMarginTop(0);
roundShape.getTextBox().setInternalMarginBottom(0);
roundShape.getTextBox().setInternalMarginLeft(0);
roundShape.getTextBox().setInternalMarginRight(0);

// Put content into the round shape.
Paragraph shapeContent = new Paragraph(doc);
shapeContent.getParagraphBreakFont().setSize(8);
Run shapeContentText = new Run(doc, "123");
shapeContentText.getFont().setSize(8);
shapeContent.appendChild(shapeContentText);
roundShape.appendChild(shapeContent);

// Create an arrow shape
Shape arrowShape = new Shape(doc, ShapeType.LINE);
arrowShape.setWidth(20);
arrowShape.setHeight(1);
arrowShape.getStroke().setEndArrowType(ArrowType.OPEN);
arrowShape.setStrokeColor(Color.ORANGE);
arrowShape.setStrokeWeight(2);
arrowShape.setRotation(-10);

// Adjustposition of the shapes.
roundShape.setWrapType(WrapType.NONE);
roundShape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
roundShape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
roundShape.setLeft(100);
roundShape.setTop(200);

arrowShape.setWrapType(WrapType.NONE);
arrowShape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
arrowShape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
arrowShape.setLeft(120);
arrowShape.setTop(205);

// Insert the shapes into the document.
doc.getFirstSection().getBody().getFirstParagraph().appendChild(roundShape);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(arrowShape);

doc.save("out.docx"); 

@muyoungko There is a mistake in your code. Instead of this:

roundShape.setWidth(20);
roundShape.setWidth(20);

You should use this:

roundShape.setWidth(20);
roundShape.setHeight(20);
1 Like

Thank you~ It is solved~

I have more question

I want to turn off “Do not rotate text” option, and set “Vertical Alignment” to Middle.

How to do this?

@muyoungko Unfortunately, currently you can only create VML shapes using Aspose.Words public API. I am afraid this kind of shapes does not have such options. These options are available in DML shapes.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-24883

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.