Adding shapes in aspose document

hi,

is it possible to add or draw multiple shapes (in example : lines) into each pages of aspose word document ?

The purpose of these shapes is for adding lines for omr purposes.
If possible, is there any sample code to achieve this?

Regards,

hadi teo

Hi Hadi,

Thanks for your inquiry. Please note that Microsoft Word document is a flow document and it does not contain any information about its layout into lines and pages. I am afraid, you can’t move cursor to a particular page in Word document. However, you can move the cursor to any place in Document and insert a Shape node of your choice by using the code like below:

DocumentBuilder builder = new DocumentBuilder();
builder.MoveToDocumentEnd();
Shape line = new Shape(builder.Document, ShapeType.Line);
line.Width = 3 * 72; 
line.StrokeColor = Color.Red;
builder.InsertNode(line);
builder.Document.Save(@"C:\Temp\out.docx");

I hope, this helps.

Best regards,

Hi Awais,
Thanks very much for your assistance. Your code snippet really helps me.
I am wondering about the “Shape” object. There are two properties which are “top” and “left”. But what are the default point of references where Aspose will calculate those values ?
For your information, my document is in landscape mode.
Another question, is the “Shape” object staying on the top of the Aspose document itself ? Because i will need to draw those shapes outside the document margin.
Regards,
hadi teo

Hi Hadi,

Thanks for your inquiry. You can use DocuemntBuilder.MoveToXXX methods to move cursor to the necessary position. After inserting an image/shape, you can change its formation how it is needed. For instance, please see the following code to be able to make the Shape float, put it behind text and set it’s position on the page:

DocumentBuilder builder = new DocumentBuilder();
builder.Writeln("some text");
builder.MoveToDocumentEnd();
Shape shape = builder.InsertImage(@"C:\Temp\Aspose.Words.png");
shape.Width= 300;
shape.Height = 300;
shape.Top = 100;
shape.Left = 100;
shape.WrapType = WrapType.None;
shape.BehindText = true;
builder.Document.Save(@"C:\Temp\out.docx");

I hope, this helps.

Best regards,

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

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