public class WrapSide
Example:
Document doc = new Document(getMyDir() + "Textboxes in drawing canvas.docx");
// This gets a live collection of all shape nodes in the document
NodeCollection shapeCollection = doc.getChildNodes(NodeType.SHAPE, true);
// Since we will be adding/removing nodes, it is better to copy all collection
// into a fixed size array, otherwise iterator will be invalidated
Node[] shapes = shapeCollection.toArray();
for (Node node : shapes) {
Shape shape = (Shape) node;
// Filter out all shapes that we don't need
if (shape.getShapeType() == ShapeType.TEXT_BOX) {
// Create a new shape that will replace the existing shape
Shape image = new Shape(doc, ShapeType.IMAGE);
// Load the image into the new shape
image.getImageData().setImage(getImageDir() + "Windows MetaFile.wmf");
// Make new shape's position to match the old shape
image.setLeft(shape.getLeft());
image.setTop(shape.getTop());
image.setWidth(shape.getWidth());
image.setHeight(shape.getHeight());
image.setRelativeHorizontalPosition(shape.getRelativeHorizontalPosition());
image.setRelativeVerticalPosition(shape.getRelativeVerticalPosition());
image.setHorizontalAlignment(shape.getHorizontalAlignment());
image.setVerticalAlignment(shape.getVerticalAlignment());
image.setWrapType(shape.getWrapType());
image.setWrapSide(shape.getWrapSide());
// Insert new shape after the old shape and remove the old shape
shape.getParentNode().insertAfter(image, shape);
shape.remove();
}
}
doc.save(getArtifactsDir() + "Shape.ReplaceTextboxesWithImages.docx");
Field Summary | ||
---|---|---|
static final int | BOTH | |
The document text wraps on both sides of the shape.
|
||
static final int | LEFT | |
The document text wraps on the left side of the shape only. There is a text free area on the right of the shape.
|
||
static final int | RIGHT | |
The document text wraps on the right side of the shape only. There is a text free area on the left side of the shape.
|
||
static final 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 final int | DEFAULT | |
Default value is |
public static final int BOTH
public static final int LEFT
public static final int RIGHT
public static final int LARGEST
public static final int DEFAULT