How can I insert absolute position line in aspose.words for java?

Hi,
How can I insert absolute position line in aspose.words for java?

Hi Zhu,

Thanks for your inquiry.

I would like to mention here that Microsoft Word document is a flow document and it does not contain any information about its layout into lines and pages. By absolute location, if you mean to ask if we can insert a line at a Point(x, y) in the document, then I am afraid, it is not possible. Aspose.Words does allow insertion of Shape node anywhere in the document. Following code snippet should help you in inserting line at the end of document:

String csPath = "C:\\Temp\\"; Document document = new Document(csPath+"test.docx");
// Create a LINE shape, set its width, color etc Shape shape = new Shape(document, ShapeType.LINE); shape.setWidth(200); shape.setStrokeColor(Color.RED);
// Create a document builder and move to end of document. DocumentBuilder builder = new DocumentBuilder(document);
builder.moveToDocumentEnd();
// Insert line shape in document using Document Builder. builder.insertNode(shape);

// Save document document.save(csPath+"testLineSaved.docx");

You can also play with setTop(double) and setLeft(double) methods of Shape class to control display of line to a custom location if required. You can also use setWrapType(WrapType) to specify how the text is wrapped around the shape. You can also use DocumentBuilder class to traverse through the Nodes in the document and add shapes wherever required. You can also move cursor to the position of your interest in the document using DocuemntBuilder.MoveTo___ methods. For further details please visit here to look into DocumentBuilder class reference and here to look into Shape class reference for Java.

Hope this helps. Please do let us know if you have any more queries.