Hi, please help.
I need to insert a shape on the first page into existing document(DOCX). Then I need to set a specific width for shape. But the shape in any case cuts the size to the size of the entered text.
I’m using version: aspose.words 19.8.jar
Screenshot_8.jpg (26.6 KB)
private Shape insertStrShape(String str, DocumentBuilder documentBuilder,
double topPosition, double leftPos, double initWidth, int textAlignment) throws Exception {
documentBuilder.moveToDocumentStart();
documentBuilder.moveTo(documentBuilder.getCurrentSection().getBody().getFirstParagraph());
Shape strShape = documentBuilder.insertShape(ShapeType.TEXT_BOX,
RelativeHorizontalPosition.PAGE, leftPos,
RelativeVerticalPosition.PAGE, topPosition,
initWidth,
9.637795,
WrapType.NONE);
strShape.setWidth(initWidth);
strShape.setZOrder(Constants.SHAPE_Z_ORDER);
// strShape.setStroked(false);
strShape.setFilled(false);
strShape.getTextBox().setInternalMarginTop(0);
strShape.getTextBox().setInternalMarginBottom(0);
strShape.getTextBox().setInternalMarginLeft(0);
strShape.getTextBox().setInternalMarginRight(0);
strShape.getTextBox().setTextBoxWrapMode(TextBoxWrapMode.NONE);
strShape.getTextBox().setFitShapeToText(false);
documentBuilder.moveTo(strShape.getFirstParagraph());
documentBuilder.write(str);
//default line spacing 1.0: ParagraphFormatting LineSpacingRule property default value
documentBuilder.getParagraphFormat().setLineSpacingRule(LineSpacingRule.MULTIPLE);
documentBuilder.getParagraphFormat().setLineSpacing(12);
documentBuilder.getParagraphFormat().setAlignment(textAlignment);
Run run = strShape.getFirstParagraph().getRuns().get(0);
run.getFont().clearFormatting();
run.getFont().setName(“Times New Roman”);
run.getFont().setSize(8);
run.getFont().setColor(Color.BLACK);
return strShape;
}