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.
Instead of 0, you can try specifying 72 value inside the setInternalMarginLeft property. The following code produces expected output: awjava-19.10.zip (5.4 KB)
Document doc = new Document();
DocumentBuilder documentBuilder = new DocumentBuilder(doc);
documentBuilder.moveToDocumentStart();
documentBuilder.moveTo(documentBuilder.getCurrentSection().getBody().getFirstParagraph());
Shape strShape = documentBuilder.insertShape(ShapeType.TEXT_BOX,
RelativeHorizontalPosition.PAGE, 288,
RelativeVerticalPosition.PAGE, 288,
144,
9.637795,
WrapType.NONE);
strShape.setWidth(200);
//strShape.setZOrder(Constants.SHAPE_Z_ORDER);
// strShape.setStroked(false);
strShape.setFilled(false);
strShape.getTextBox().setInternalMarginTop(0);
strShape.getTextBox().setInternalMarginBottom(0);
strShape.getTextBox().setInternalMarginLeft(72);
strShape.getTextBox().setInternalMarginRight(0);
strShape.getTextBox().setTextBoxWrapMode(TextBoxWrapMode.NONE);
strShape.getTextBox().setFitShapeToText(false);
documentBuilder.moveTo(strShape.getFirstParagraph());
documentBuilder.write("HELLO");
//default line spacing 1.0: ParagraphFormatting LineSpacingRule property default value
documentBuilder.getParagraphFormat().setLineSpacingRule(LineSpacingRule.MULTIPLE);
documentBuilder.getParagraphFormat().setLineSpacing(12);
documentBuilder.getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT);
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);
doc.save("E:\\Temp\\awjava-19.10.docx");
If the length of the text in 2 different shapes is different then they will differ in the width of the shape, I need the shapes to have the same specified width and not depend on the length of the entered text.
Text alignment in a shape can be right/left.
I also need to set a static position for this shapes.