When creating a group of shapes in which one object is directly in the other, the error occurs such that there is no possibility of stretching the inner element and no text appears in it.
Java Code:
import com.aspose.words.Font;
import com.aspose.words.Shape;
import com.aspose.words.*;
import java.awt.*;
import java.io.File;
public class Example {
public static void main(String[] args) throws Exception {
overlapping();
}
public static void overlapping() throws Exception {
// Create empty docx
com.aspose.words.Document doc = new Document();
doc.removeAllChildren();
Section section = new Section(doc);
doc.appendChild(section);
DocumentBuilder builder = new DocumentBuilder(doc);
//Page setup
PageSetup ps = builder.getPageSetup();
ps.setPageWidth(595.275634765625);
ps.setPageHeight(841.8897705078125);
ps.setOrientation(Orientation.PORTRAIT);
ps.setTopMargin(17.00787353515625);
ps.setBottomMargin(28.346435546875);
ps.setLeftMargin(17.00787353515625);
ps.setRightMargin(28.34649658203125);
// box 1
Shape outerShape = new Shape(builder.getDocument(), ShapeType.TEXT_BOX);
outerShape.setWrapType(WrapType.NONE);
outerShape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
outerShape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
outerShape.appendChild(new Paragraph(builder.getDocument()));
outerShape.setFillColor(new Color(255, 255, 0));
outerShape.setStrokeColor(new Color(0, 0, 0));
outerShape.getFill().setOpacity(1.0);
outerShape.setStrokeWeight(1.0);
outerShape.setBehindText(true);
outerShape.setWidth(217.04967685008614);
outerShape.setHeight(21.67716535433071);
outerShape.setTop(185.6828435462291);
outerShape.setLeft(85.53939170537033);
outerShape.setZOrder(1);
Run run = new Run(builder.getDocument(), "ValueInputGraph - Label:");
Font runFont = run.getFont();
runFont.setName("Dialog");
runFont.setSize(10);
runFont.setBold(false);
runFont.setItalic(false);
outerShape.getLastParagraph().appendChild(run);
outerShape.getTextBox().setVerticalAnchor(TextBoxAnchor.MIDDLE);
// Second box
Shape inputField = new Shape(builder.getDocument(), ShapeType.TEXT_BOX);
inputField.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
inputField.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
inputField.setWidth(ConvertUtil.millimeterToPoint(30.204787731170654));
inputField.getTextBox().setFitShapeToText(true);
inputField.setStroked(true);
inputField.setFillColor(new Color(255, 255, 255));
inputField.setHeight(12.450000000000001);
inputField.setTop(189.79642622339446);
inputField.setLeft(213.96919780641093);
inputField.setZOrder(3);
TextBox textBox = inputField.getTextBox();
textBox.setInternalMarginRight(0);
textBox.setInternalMarginLeft(0);
textBox.setInternalMarginTop(0);
textBox.setInternalMarginBottom(0);
Run run2 = new Run(builder.getDocument(), "Inputtext");
Font runFont2 = run2.getFont();
runFont2.setName("Tahoma");
runFont2.setSize(10);
runFont2.setBold(false);
runFont2.setItalic(false);
inputField.appendChild(new Paragraph(builder.getDocument()));
inputField.getLastParagraph().appendChild(run2);
// group from 1 and 2 box
GroupShape group = new GroupShape(builder.getDocument());
group.appendChild(outerShape);
group.appendChild(inputField);
double height = outerShape.getHeight();
double width = outerShape.getWidth();
group.setTop(outerShape.getTop());
group.setLeft(outerShape.getLeft());
group.setWidth(width);
group.setHeight(height);
group.setDistanceLeft(0);
group.setDistanceRight(0);
group.setZOrder(outerShape.getZOrder());
group.setAllowOverlap(true);
group.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
group.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
group.setCoordSize(new Dimension((int) Math.ceil(width),(int) Math.ceil(height)));
builder.insertNode(group);
OoxmlSaveOptions options = new OoxmlSaveOptions();
options.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT);
doc.save(System.getProperty("user.dir") + File.separator + "overlap.docx",options);
}
}
Reproduce result: run code
Expected result: In result file (after run code) in MsWord click on "ValueInputGraph " —> Shape Format --> Group Objects --> Ungroup --> Group Objects --> Group
In addition, I would like to know how you can lock the possibility of editing individual shapes.
Like in MsWord:
Developer --> Rich Text Coontro Context --> Write some text --> Developer --> Restrict Editing --> Editing restrictions --> Mark combobox ( Allow only…) and choose No Changes/ Filling in form --> Start Enforcment --> yes, Start enforcing protection --> Ok (without password)