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

Free Support Forum - aspose.com

Drawing Shape in Aspose Words Java

Hello Aspose Teams, I want to ask about drawing an image.


This is the problem.

I want to create a document like in the Attachment, please open it first.

I can make the header logo and watermark just like in the Example.doc. But i can not make the border, because the border was actually not the page border, but it was a drawing shape that placed in header section. How can i make the output just like in the Attachment ? I search in aspose api and example about Drawing Shape but could’n find it

Thanks

Hi Ano Rangga,

Thanks for your inquiry. Please use the following code example to achieve your requirements. Hope this helps you. I have attached the output document with this post for your kind reference. Please get the code of insertWatermarkText from here:
http://www.aspose.com/docs/display/wordsjava/How+to++Add+a+Watermark+to+a+Document


Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = new Shape(doc, ShapeType.TEXT_BOX);

shape.setWidth(doc.getFirstSection().getPageSetup().getPageWidth() - 100);

shape.setHeight(doc.getFirstSection().getPageSetup().getPageHeight()- 100);

shape.setWrapType(WrapType.NONE);

shape.setBehindText(true);

shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);

shape.setHorizontalAlignment(HorizontalAlignment.CENTER);

shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);

shape.setVerticalAlignment(VerticalAlignment.CENTER);

shape.setStroked(true);

shape.setStrokeColor(Color.yellow);

shape.setStrokeWeight(1);

shape.appendChild(new Paragraph(doc));

Paragraph para = shape.getFirstParagraph();

para.appendChild(new Run(doc, ""));

builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);

builder.insertNode(shape);

insertWatermarkText(doc, "WaterMark");

builder.moveTo(para);

Shape image = builder.insertImage(MyDir + "in.png");

para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

doc.save(MyDir + "Out.docx");