Hello. I need to add a text box with internal margins = 0 to the existing document (textbox-margin.docx) on archive. I need to add it to the first paragraph on the document. But this paragraph has a preset margins(11, 11).
For some reason my shape inherits these values and I cannot set other values manually.
Please help how I can do it?
private void insertShape() throws Exception {
Document document = new Document("textbox-margin.docx");
Shape strShape = new Shape(document, ShapeType.TEXT_BOX);
strShape.setTop(10);
strShape.setLeft(10);
strShape.setWidth(40);
strShape.setHeight(40);
strShape.getTextBox().setInternalMarginTop(0);
strShape.getTextBox().setInternalMarginBottom(0);
strShape.getTextBox().setInternalMarginLeft(0);
strShape.getTextBox().setInternalMarginRight(0);
strShape.appendChild(new Paragraph(document));
Paragraph para = strShape.getFirstParagraph();
para.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
Run run = new Run(document);
run.setText("text");
para.appendChild(run);
document.getFirstSection().getBody().getFirstParagraph().appendChild(strShape);
document.save(UUID.randomUUID() + ".docx", SaveFormat.DOCX);
}
textbox-margin.zip (45.4 KB)