public class WrapSide
extends java.lang.Object
Examples:
Shows how to replace all textbox shapes with image shapes.
Document doc = new Document(getMyDir() + "Textboxes in drawing canvas.docx");
List<Shape> shapeList = Arrays.stream(doc.getChildNodes(NodeType.SHAPE, true).toArray())
.filter(Shape.class::isInstance)
.map(Shape.class::cast)
.collect(Collectors.toList());
Assert.assertEquals(3, IterableUtils.countMatches(shapeList, s -> s.getShapeType() == ShapeType.TEXT_BOX));
Assert.assertEquals(1, IterableUtils.countMatches(shapeList, s -> s.getShapeType() == ShapeType.IMAGE));
for (Shape shape : shapeList) {
if (((shape.getShapeType()) == (ShapeType.TEXT_BOX))) {
Shape replacementShape = new Shape(doc, ShapeType.IMAGE);
replacementShape.getImageData().setImage(getImageDir() + "Logo.jpg");
replacementShape.setLeft(shape.getLeft());
replacementShape.setTop(shape.getTop());
replacementShape.setWidth(shape.getWidth());
replacementShape.setHeight(shape.getHeight());
replacementShape.setRelativeHorizontalPosition(shape.getRelativeHorizontalPosition());
replacementShape.setRelativeVerticalPosition(shape.getRelativeVerticalPosition());
replacementShape.setHorizontalAlignment(shape.getHorizontalAlignment());
replacementShape.setVerticalAlignment(shape.getVerticalAlignment());
replacementShape.setWrapType(shape.getWrapType());
replacementShape.setWrapSide(shape.getWrapSide());
shape.getParentNode().insertAfter(replacementShape, shape);
shape.remove();
}
}
shapeList = Arrays.stream(doc.getChildNodes(NodeType.SHAPE, true).toArray())
.filter(Shape.class::isInstance)
.map(Shape.class::cast)
.collect(Collectors.toList());
Assert.assertEquals(0, IterableUtils.countMatches(shapeList, s -> s.getShapeType() == ShapeType.TEXT_BOX));
Assert.assertEquals(4, IterableUtils.countMatches(shapeList, s -> s.getShapeType() == ShapeType.IMAGE));
doc.save(getArtifactsDir() + "Shape.ReplaceTextboxesWithImages.docx");
| Modifier and Type | Field and Description |
|---|---|
static int |
BOTH
The document text wraps on both sides of the shape.
|
static int |
DEFAULT
Default value is
BOTH. |
static int |
LARGEST
The document text wraps on the side of the shape that is farthest from the page margin, leaving text free area on the other side of the shape.
|
static int |
LEFT
The document text wraps on the left side of the shape only.
|
static int |
length |
static int |
RIGHT
The document text wraps on the right side of the shape only.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
fromName(java.lang.String wrapSideName) |
static java.lang.String |
getName(int wrapSide) |
static int[] |
getValues() |
static java.lang.String |
toString(int wrapSide) |
public static int BOTH
public static int LEFT
public static int RIGHT
public static int LARGEST
public static int DEFAULT
BOTH.public static int length