Free Support Forum - aspose.com

How to render Shape inside the Aspose document

Hi,

My main objective is to add 'Shape' object inside the Aspose document.

Currently we are using VBA macro to render Shape object (which is a line) in each individual pages.

I have read the following article, but it seems not relevant to me.

http://www.aspose.com/docs/display/wordsnet/About+Shapes+in+Aspose.Words

May i know is it possible to render 'Shape' object inside Aspose document ? Is there any code snippet for this ?

Regards,

hadi teo

Hi Hadi,


Thanks for your inquiry. Please use the following code snippets for your requirements and read Shape Types from following documentation link:
http://www.aspose.com/docs/display/wordsnet/ShapeType+Enumeration

The Shape Class represents an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture. Using the Shape class you can create or modify shapes in a Microsoft Word document.

//Create document<o:p></o:p>

Document doc = new Document();<o:p></o:p>

//Create DocumentBuilder<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);<o:p></o:p>

//Insert some text<o:p></o:p>

builder.Write(“This is text before shape”);<o:p></o:p>

//Create elipse shape<o:p></o:p>

Shape elipse = new Shape(doc, ShapeType.Ellipse);<o:p></o:p>

//Set size of shape<o:p></o:p>

elipse.Width = 120;<o:p></o:p>

elipse.Height = 100;<o:p></o:p>

//Set WrapType<o:p></o:p>

elipse.WrapType = WrapType.Inline;<o:p></o:p>

//Insert shape into the document<o:p></o:p>

builder.InsertNode(elipse);<o:p></o:p>

//Insert some text<o:p></o:p>

builder.Write(“Some text sfter shape”);<o:p></o:p>

//Save document<o:p></o:p>

doc.Save(@“Test057\out.doc”);


==============================================================

<span style=“font-size:10.0pt;
font-family:“Courier New”;color:#2B91AF;mso-font-kerning:0pt;mso-ansi-language:
PL;mso-no-proof:yes”>Document

<span style=“font-size:10.0pt;font-family:
“Courier New”;mso-font-kerning:0pt;mso-ansi-language:PL;mso-no-proof:yes”> doc
= new Document();<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

//Create Line Shape

Shape line = new Shape(doc, ShapeType.Line);

// Specify width of the shape.

line.Width = 100;

// Set line width.

line.Stroke.Weight = 5;

//Insert shape into the document

builder.InsertNode(line);

//Save document

doc.Save(MyDir + @"out.doc");