Need help in drawing Shapes in MSWord

Team,

I am using Aspose latest version for document conversion. I am trying to create round rectangle shape using below api.

Shape shape = new Shape(doc, ShapeType.ROUND_RECTANGLE); 
shape.setWrapType(WrapType.NONE);
shape.setHorizontalAlignment(HorizontalAlignment.CENTER);
shape.setVerticalAlignment(VerticalAlignment.TOP);
shape.setHeight(200);
shape.setWidth(600); 

Shape is created as expected. But now my requirement is to set the corner radius of rectangle. Is there any api to set it ??.
Please see the attached image to make it understand better
Thanks,
Anbu

Hi Anbu,

Thanks for your inquiry. Unfortunately, Aspose.Words does not support the requested feature at the moment. However, we have already logged this feature request as WORDSNET-5854 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

Thanks for the reply.
After creating shape using Aspose api as below, i am trying to set text “ANBU”. But text is positioned at top of the shape as shown in image. I want text to be align at middle of the shape. please help me

Shape textBox = new Shape(doc, ShapeType.RECTANGLE);

textBox.setWrapType(WrapType.NONE);
textBox.setHeight(200);
textBox.setWidth(200);
textBox.setHorizontalAlignment(HorizontalAlignment.CENTER);
textBox.setVerticalAlignment(VerticalAlignment.BOTTOM);

textBox.getTextPath().setFitPath(true);

textBox.appendChild(new Paragraph(doc));
Paragraph para = textBox.getFirstParagraph();
para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
Run run = new Run(doc);
run.setText("ANBU");
para.appendChild(run);

Hi Anbu,

Thanks for your inquiry. Unfortunately, setting the vertically alignment of textbox is not available at the moment in Aspose.Words. However, we had already logged this feature request as WORDSNET-2201 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

Team,

I am trying to import the document containing shapes. Using aspose api shapenode.getNodeType() , i am trying to get shape type. But it is always returning node type as 14 for all shapes. Am i doing anything wrong ??

Regards,
Anbu

Hi Anbu,

Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v14.6.0) from here and let us know how it goes on your side. Please try the following code example at your end. Hope this helps you.

Document doc = new Document(MyDir + "input.docx");
for(Node node : (Iterable)doc.getChildNodes(NodeType.ANY, true))
{
     System.out.println(node.getNodeType());
}

Thanks for the reply. Think you didnt understand my question.I have two shapes in the attached document. I am trying to get the shape node type, but it is always throwing same shape node type
Here is my code

NodeList drawNodes = doc.selectNodes("//DrawingML");

for (Node drawNode : drawNodes)
{
    DrawingML drawml = (DrawingML)drawNodes.get(0);
    System.out.println("DrwaingML:::" + drawml.getNodeType());
    drawml.toString(SaveFormat.HTML);// This line converting DrawingML to Shape.
                                        // Dont know why|how it is converting. Anyway i need this as DrawingML api 
                                        // is much limited
}

NodeList shapeNode = doc.selectNodes("//Shape");

for (int i = 0, count = shapeNode.getCount(); i < count; i++)
{

    System.out.println("ShapeData:::" + ((Shape)shapeNode.get(i)).getNodeType());
}

Output:

DrwaingML:::34
DrwaingML:::34
ShapeData:::18
ShapeData:::18

Note : I am using Aspose latest version .

Hi Anbu,

Thanks for sharing the detail. If you save the shared input document to HTML file format, the DrawingML nodes are converted to Shape nodes. Could you please share why you are converting DrawingML to HTML format using Node.toString(SaveFormat.HTML) method. We will then provide you more information about your query.

We are converting into html because DrawingML API is very limited in Aspose where as Shape class as more API.

There is no method in DrawingML to find shape type.

I need to find the Shape/DrawingML type like is RECTANGLE or ROUND_RECTANGLE or CUBE etc …

Hi Anbu,

Thanks for sharing the detail. Please use the Shape.ShapeType property to get the shape type like Rectangle, Ellipse etc.

NodeList shapeNode = doc.selectNodes("//Shape");
for (int i = 0, count = shapeNode.getCount(); i < count; i++)
{
    System.*out*.println("ShapeData:::" + ((Shape)shapeNode.get(i)).getNodeType());
    System.*out*.println("ShapeType:::" + ((Shape)shapeNode.get(i)).getShapeType());
}

Unfortunately, Aspose.Words does not support the requested feature for DrawingML node at the moment. However, I have logged this feature request as WORDSNET-10507 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-10507) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.