public class Shape extends ShapeBase
To learn more, visit the Working with Shapes documentation article.
Remarks:
Using the Shape class you can create or modify shapes in a Microsoft Word document.
An important property of a shape is its ShapeBase.getShapeType(). Shapes of different types can have different capabilities in a Word document. For example, only image and OLE shapes can have images inside them. Most of the shapes can have text, but not all.
Shapes that can have text, can contain Paragraph and Table nodes as children.
Examples:
Shows how to insert a floating image to the center of a page.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a floating image that will appear behind the overlapping text and align it to the page's center.
Shape shape = builder.insertImage(getImageDir() + "Logo.jpg");
shape.setWrapType(WrapType.NONE);
shape.setBehindText(true);
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
shape.setHorizontalAlignment(HorizontalAlignment.CENTER);
shape.setVerticalAlignment(VerticalAlignment.CENTER);
doc.save(getArtifactsDir() + "Image.CreateFloatingPageCenter.docx");
Shows how to extract images from a document, and save them to the local file system as individual files.
Document doc = new Document(getMyDir() + "Images.docx");
// Get the collection of shapes from the document,
// and save the image data of every shape with an image as a file to the local file system.
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
int imageIndex = 0;
for (Shape shape : (Iterable<Shape>) shapes) {
if (shape.hasImage()) {
// The image data of shapes may contain images of many possible image formats.
// We can determine a file extension for each image automatically, based on its format.
String imageFileName = MessageFormat.format("File.ExtractImages.{0}{1}", imageIndex, FileFormatUtil.imageTypeToExtension(shape.getImageData().getImageType()));
shape.getImageData().save(getArtifactsDir() + imageFileName);
imageIndex++;
}
}
Shows how to delete all shapes from a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert two shapes along with a group shape with another shape inside it.
builder.insertShape(ShapeType.RECTANGLE, 400.0, 200.0);
builder.insertShape(ShapeType.STAR, 300.0, 300.0);
GroupShape group = new GroupShape(doc);
group.setBounds(new Rectangle2D.Float(100f, 50f, 200f, 100f));
group.setCoordOrigin(new Point(-1000, -500));
Shape subShape = new Shape(doc, ShapeType.CUBE);
subShape.setWidth(500.0);
subShape.setHeight(700.0);
subShape.setLeft(0.0);
subShape.setTop(0.0);
group.appendChild(subShape);
builder.insertNode(group);
Assert.assertEquals(doc.getChildNodes(NodeType.SHAPE, true).getCount(), 3);
Assert.assertEquals(doc.getChildNodes(NodeType.GROUP_SHAPE, true).getCount(), 1);
// Remove all Shape nodes from the document.
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
shapes.clear();
// All shapes are gone, but the group shape is still in the document.
Assert.assertEquals(doc.getChildNodes(NodeType.GROUP_SHAPE, true).getCount(), 1);
Assert.assertEquals(doc.getChildNodes(NodeType.SHAPE, true).getCount(), 0);
// Remove all group shapes separately.
NodeCollection groupShapes = doc.getChildNodes(NodeType.GROUP_SHAPE, true);
groupShapes.clear();
Assert.assertEquals(doc.getChildNodes(NodeType.GROUP_SHAPE, true).getCount(), 0);
Assert.assertEquals(doc.getChildNodes(NodeType.SHAPE, true).getCount(), 0);
ShapeBase,
GroupShape| Constructor and Description |
|---|
Shape(DocumentBase doc,
int shapeType)
Initializes a new instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(DocumentVisitor visitor)
Accepts a visitor.
|
int |
acceptEnd(DocumentVisitor visitor)
Accepts a visitor for visiting the end of the shape.
|
int |
acceptStart(DocumentVisitor visitor)
Accepts a visitor for visiting the start of the shape.
|
AdjustmentCollection |
getAdjustments()
Provides access to the adjustment raw values of a shape.
|
Chart |
getChart()
Provides access to the chart properties if this shape has a
Chart. |
int |
getDashStyle() |
int |
getEndArrowLength() |
int |
getEndArrowType() |
int |
getEndArrowWidth() |
int |
getEndCap() |
boolean |
getExtrusionEnabled()
Returns
true if an extrusion effect is enabled. |
java.awt.Color |
getFillColor()
Defines the brush color that fills the closed path of the shape.
|
boolean |
getFilled()
Determines whether the closed path of the shape will be filled.
|
Paragraph |
getFirstParagraph()
Gets the first paragraph in the shape.
|
float |
getHorizontalMargins_ITextBox() |
HorizontalRuleFormat |
getHorizontalRuleFormat()
Provides access to the properties of the horizontal rule shape.
|
ImageData |
getImageData()
Provides access to the image of the shape.
|
int |
getJoinStyle() |
Paragraph |
getLastParagraph()
Gets the last paragraph in the shape.
|
int |
getLineFillType() |
int |
getLineStyle() |
byte |
getMarkupLanguage_ITextBox() |
int |
getNodeType()
Returns
NodeType.SHAPE. |
OleFormat |
getOleFormat()
Provides access to the OLE data of a shape.
|
boolean |
getShadowEnabled()
Returns
true if a shadow effect is enabled. |
SignatureLine |
getSignatureLine()
Gets
SignatureLine object if the shape is a signature line. |
int |
getStartArrowLength() |
int |
getStartArrowType() |
int |
getStartArrowWidth() |
int |
getStoryType()
Returns
StoryType.TEXTBOX. |
Stroke |
getStroke()
Defines a stroke for a shape.
|
int |
getStrokeBackThemeColor() |
double |
getStrokeBackTintAndShade() |
java.awt.Color |
getStrokeColor()
Defines the color of a stroke.
|
boolean |
getStroked()
Defines whether the path will be stroked.
|
int |
getStrokeForeThemeColor() |
double |
getStrokeForeTintAndShade() |
byte[] |
getStrokeImageBytes() |
double |
getStrokeTransparency() |
boolean |
getStrokeVisible() |
double |
getStrokeWeight()
Defines the brush thickness that strokes the path of a shape in points.
|
TextBox |
getTextBox()
Defines attributes that specify how text is displayed in a shape.
|
int |
getTextboxLayoutFlow_ITextBox() |
int |
getTextBoxWrapMode_ITextBox() |
TextPath |
getTextPath()
Defines the text of the text path (of a WordArt object).
|
double |
getWeight() |
boolean |
hasChart()
|
boolean |
hasImage()
Returns
true if the shape has image bytes or links an image. |
boolean |
hasSmartArt()
Returns
true if this Shape has a SmartArt object. |
boolean |
hasVerticalTextFlow_ITextBox() |
void |
setDashStyle(int value) |
void |
setEndArrowLength(int value) |
void |
setEndArrowType(int value) |
void |
setEndArrowWidth(int value) |
void |
setEndCap(int value) |
void |
setFillColor(java.awt.Color value)
Defines the brush color that fills the closed path of the shape.
|
void |
setFilled(boolean value)
Determines whether the closed path of the shape will be filled.
|
void |
setJoinStyle(int value) |
void |
setLineFillType(int value) |
void |
setLineStyle(int value) |
void |
setStartArrowLength(int value) |
void |
setStartArrowType(int value) |
void |
setStartArrowWidth(int value) |
void |
setStrokeBackThemeColor(int value) |
void |
setStrokeBackTintAndShade(double value) |
void |
setStrokeColor(java.awt.Color value)
Defines the color of a stroke.
|
void |
setStroked(boolean value)
Defines whether the path will be stroked.
|
void |
setStrokeForeThemeColor(int value) |
void |
setStrokeForeTintAndShade(double value) |
void |
setStrokeTransparency(double value) |
void |
setStrokeVisible(boolean value) |
void |
setStrokeWeight(double value)
Defines the brush thickness that strokes the path of a shape in points.
|
void |
setWeight(double value) |
void |
updateSmartArtDrawing()
Updates SmartArt pre-rendered drawing by using Aspose.Words's SmartArt cold rendering engine.
|
adjustWithEffects, canHaveImage, clearRunAttrs, fetchInheritedRunAttr, fetchInheritedShapeAttr, fetchShapeAttr, getAllowOverlap, getAlternativeText, getAnchorLocked, getAspectRatioLocked, getBehindText, getBlur, getBottom, getBounds, getBoundsInPoints, getBoundsWithEffects, getColor, getCoordOrigin, getCoordSize, getDirectRunAttr, getDirectRunAttr, getDirectShapeAttr, getDistance, getDistanceBottom, getDistanceLeft, getDistanceRight, getDistanceTop, getDocument_IInline, getEdgeRadius, getFill, getFillableBackColor, getFillableBackThemeColor, getFillableBackTintAndShade, getFillableBaseForeColor, getFillableForeColor, getFillableForeThemeColor, getFillableForeTintAndShade, getFillableImageBytes, getFillableTransparency, getFillableVisible, getFilledColor, getFillType, getFlipOrientation, getFont, getGlow, getGradientAngle, getGradientStops, getGradientStyle, getGradientVariant, getHeight, getHeightRelative, getHidden, getHorizontalAlignment, getHRef, getLeft, getLeftRelative, getMarkupLanguage, getName, getOldOn, getOldOpacity, getParentParagraph_IInline, getParentParagraph, getPatternType, getPresetTexture, getRadius, getReflection, getReflectionSize, getReflectionTransparency, getRelativeHorizontalPosition, getRelativeHorizontalSize, getRelativeVerticalPosition, getRelativeVerticalSize, getRight, getRotateWithObject, getRotation, getScreenTip, getShadowColors, getShadowFormat, getShadowTransparency, getShadowType, getShapeRenderer, getShapeType, getSizeInPoints, getSoftEdge, getTarget, getTextureAlignment, getTitle, getTop, getTopRelative, getTransparency, getVerticalAlignment, getVisible, getWidth, getWidthRelative, getWrapSide, getWrapType, getZOrder_IShape, getZOrder, isDecorative, isDecorative, isDeleteRevision, isGroup, isHorizontalRule, isImage, isInline, isInsertRevision, isLayoutInCell, isLayoutInCell, isMoveFromRevision, isMoveToRevision, isSignatureLine, isTopLevel, isWordArt, localToParent, oneColorGradient, patterned, presetTextured, removeGlow, removeMoveRevisions, removeReflection, removeRunAttr, removeShadow, removeShapeAttr, removeSoftEdge, setAllowOverlap, setAlternativeText, setAnchorLocked, setAspectRatioLocked, setBehindText, setBlur, setBounds, setColor, setCoordOrigin, setCoordSize, setDistance, setDistanceBottom, setDistanceLeft, setDistanceRight, setDistanceTop, setEdgeRadius, setFillableBackColor, setFillableBackThemeColor, setFillableBackTintAndShade, setFillableForeColor, setFillableForeThemeColor, setFillableForeTintAndShade, setFillableTransparency, setFillableVisible, setFilledColor, setFlipOrientation, setGradientAngle, setHeight, setHeightRelative, setHidden, setHorizontalAlignment, setHRef, setImage, setLeft, setLeftRelative, setName, setOldOn, setOldOpacity, setRadius, setReflectionSize, setReflectionTransparency, setRelativeHorizontalPosition, setRelativeHorizontalSize, setRelativeVerticalPosition, setRelativeVerticalSize, setRotateWithObject, setRotation, setRunAttr, setScreenTip, setShadowColors, setShadowTransparency, setShadowType, setShapeAttr, setTarget, setTextureAlignment, setTitle, setTop, setTopRelative, setTransparency, setVerticalAlignment, setWidth, setWidthRelative, setWrapSide, setWrapType, setZOrder_IShape, setZOrder, solid, twoColorGradientacceptChildren, acceptCore, appendChild, coreRemoveSelfOnly, getChild, getChildNodes, getContainer, getCount, getCurrentNode, getFirstChild, getLastChild, getNextMatchingNode, getText, hasChildNodes, indexOf, insertAfter, insertBefore, isComposite, iterator, prependChild, removeAllChildren, removeChild, removeSmartTags, selectNodes, selectSingleNodedeepClone, getAncestor, getAncestor, getCustomNodeId, getDocument, getNextSibling, getParentNode, getPreviousSibling, getRange, memberwiseClone, nextPreOrder, nodeTypeToString, previousPreOrder, remove, setCustomNodeId, toString, toString, toString, visitorActionToBoolpublic Shape(DocumentBase doc, int shapeType)
public boolean accept(DocumentVisitor visitor) throws java.lang.Exception
Remarks:
Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.
For more info see the Visitor design pattern.
Calls DocumentVisitor.visitShapeStart(com.aspose.words.Shape), then calls Node.accept(com.aspose.words.DocumentVisitor) for all child nodes of the shape and calls DocumentVisitor.visitShapeEnd(com.aspose.words.Shape) at the end.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
accept in class Nodevisitor - The visitor that will visit the nodes.DocumentVisitor stopped the operation before visiting all nodes.java.lang.Exceptionpublic int acceptStart(DocumentVisitor visitor) throws java.lang.Exception
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
acceptStart in class CompositeNodevisitor - The document visitor.VisitorAction constants.java.lang.Exceptionpublic int acceptEnd(DocumentVisitor visitor) throws java.lang.Exception
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
acceptEnd in class CompositeNodevisitor - The document visitor.VisitorAction constants.java.lang.Exceptionpublic float getHorizontalMargins_ITextBox()
public int getStrokeForeThemeColor()
throws java.lang.Exception
java.lang.Exceptionpublic void setStrokeForeThemeColor(int value)
throws java.lang.Exception
java.lang.Exceptionpublic int getStrokeBackThemeColor()
throws java.lang.Exception
java.lang.Exceptionpublic void setStrokeBackThemeColor(int value)
throws java.lang.Exception
java.lang.Exceptionpublic double getStrokeForeTintAndShade()
public void setStrokeForeTintAndShade(double value)
public double getStrokeBackTintAndShade()
public void setStrokeBackTintAndShade(double value)
public boolean getStrokeVisible()
public void setStrokeVisible(boolean value)
public double getStrokeTransparency()
public void setStrokeTransparency(double value)
public double getWeight()
public void setWeight(double value)
public int getDashStyle()
public void setDashStyle(int value)
public int getJoinStyle()
public void setJoinStyle(int value)
public int getEndCap()
public void setEndCap(int value)
public int getLineStyle()
public void setLineStyle(int value)
public int getStartArrowType()
public void setStartArrowType(int value)
public int getEndArrowType()
public void setEndArrowType(int value)
public int getStartArrowWidth()
public void setStartArrowWidth(int value)
public int getStartArrowLength()
public void setStartArrowLength(int value)
public int getEndArrowWidth()
public void setEndArrowWidth(int value)
public int getEndArrowLength()
public void setEndArrowLength(int value)
public int getLineFillType()
public void setLineFillType(int value)
public byte[] getStrokeImageBytes()
throws java.lang.Exception
java.lang.Exceptionpublic int getNodeType()
NodeType.SHAPE.
Examples:
Shows how to traverse a composite node's tree of child nodes.
public void recurseChildren() throws Exception {
Document doc = new Document(getMyDir() + "Paragraphs.docx");
// Any node that can contain child nodes, such as the document itself, is composite.
Assert.assertTrue(doc.isComposite());
// Invoke the recursive function that will go through and print all the child nodes of a composite node.
traverseAllNodes(doc, 0);
}
/// <summary>
/// Recursively traverses a node tree while printing the type of each node
/// with an indent depending on depth as well as the contents of all inline nodes.
/// </summary>
public void traverseAllNodes(CompositeNode parentNode, int depth) {
for (Node childNode = parentNode.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) {
System.out.println(MessageFormat.format("{0}{1}", String.format(" ", depth), Node.nodeTypeToString(childNode.getNodeType())));
// Recurse into the node if it is a composite node. Otherwise, print its contents if it is an inline node.
if (childNode.isComposite()) {
System.out.println();
traverseAllNodes((CompositeNode) childNode, depth + 1);
} else if (childNode instanceof Inline) {
System.out.println(MessageFormat.format(" - \"{0}\"", childNode.getText().trim()));
} else {
System.out.println();
}
}
}
getNodeType in class NodeNodeType.SHAPE. The returned value is one of NodeType constants.public int getStoryType()
StoryType.TEXTBOX.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
StoryType.TEXTBOX. The returned value is one of StoryType constants.public boolean getExtrusionEnabled()
true if an extrusion effect is enabled.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
true if an extrusion effect is enabled.public boolean getShadowEnabled()
true if a shadow effect is enabled.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
true if a shadow effect is enabled.public Stroke getStroke()
Examples:
Shows to create a variety of shapes.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Below are four examples of shapes that we can insert into our documents.
// 1 - Dotted, horizontal, half-transparent red line
// with an arrow on the left end and a diamond on the right end:
Shape arrow = new Shape(doc, ShapeType.LINE);
arrow.setWidth(200.0);
arrow.getStroke().setColor(Color.RED);
arrow.getStroke().setStartArrowType(ArrowType.ARROW);
arrow.getStroke().setStartArrowLength(ArrowLength.LONG);
arrow.getStroke().setStartArrowWidth(ArrowWidth.WIDE);
arrow.getStroke().setEndArrowType(ArrowType.DIAMOND);
arrow.getStroke().setEndArrowLength(ArrowLength.LONG);
arrow.getStroke().setEndArrowWidth(ArrowWidth.WIDE);
arrow.getStroke().setDashStyle(DashStyle.DASH);
arrow.getStroke().setOpacity(0.5);
Assert.assertEquals(arrow.getStroke().getJoinStyle(), JoinStyle.MITER);
builder.insertNode(arrow);
// 2 - Thick black diagonal line with rounded ends:
Shape line = new Shape(doc, ShapeType.LINE);
line.setTop(40.0);
line.setWidth(200.0);
line.setHeight(20.0);
line.setStrokeWeight(5.0);
line.getStroke().setEndCap(EndCap.ROUND);
builder.insertNode(line);
// 3 - Arrow with a green fill:
Shape filledInArrow = new Shape(doc, ShapeType.ARROW);
filledInArrow.setWidth(200.0);
filledInArrow.setHeight(40.0);
filledInArrow.setTop(100.0);
filledInArrow.getFill().setForeColor(Color.GREEN);
filledInArrow.getFill().setVisible(true);
builder.insertNode(filledInArrow);
// 4 - Arrow with a flipped orientation filled in with the Aspose logo:
Shape filledInArrowImg = new Shape(doc, ShapeType.ARROW);
filledInArrowImg.setWidth(200.0);
filledInArrowImg.setHeight(40.0);
filledInArrowImg.setTop(160.0);
filledInArrowImg.setFlipOrientation(FlipOrientation.BOTH);
BufferedImage image = ImageIO.read(getAsposelogoUri().toURL().openStream());
Graphics2D graphics2D = image.createGraphics();
// When we flip the orientation of our arrow, we also flip the image that the arrow contains.
// Flip the image the other way to cancel this out before getting the shape to display it.
AffineTransform at = new AffineTransform();
at.concatenate(AffineTransform.getScaleInstance(1, -1));
at.concatenate(AffineTransform.getTranslateInstance(0, -image.getHeight()));
graphics2D.transform(at);
graphics2D.drawImage(image, 0, 0, null);
graphics2D.dispose();
filledInArrowImg.getImageData().setImage(image);
builder.insertNode(filledInArrowImg);
doc.save(getArtifactsDir() + "Drawing.VariousShapes.docx");
Stroke value.public boolean getStroked()
Remarks:
This is a shortcut to the Stroke.getOn() / Stroke.setOn(boolean) property.
The default value is true.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
boolean value.public void setStroked(boolean value)
Remarks:
This is a shortcut to the Stroke.getOn() / Stroke.setOn(boolean) property.
The default value is true.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
value - The corresponding boolean value.public double getStrokeWeight()
Remarks:
This is a shortcut to the Stroke.getWeight() / Stroke.setWeight(double) property.
The default value is 0.75.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
double value.public void setStrokeWeight(double value)
Remarks:
This is a shortcut to the Stroke.getWeight() / Stroke.setWeight(double) property.
The default value is 0.75.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
value - The corresponding double value.public java.awt.Color getStrokeColor()
Remarks:
This is a shortcut to the Stroke.getColor() / Stroke.setColor(java.awt.Color) property.
The default value is java.awt.Color#getBlack().
Examples:
Shows how to fill a shape with a solid color.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Write some text, and then cover it with a floating shape.
builder.getFont().setSize(32.0);
builder.writeln("Hello world!");
Shape shape = builder.insertShape(ShapeType.CLOUD_CALLOUT, RelativeHorizontalPosition.LEFT_MARGIN, 25.0,
RelativeVerticalPosition.TOP_MARGIN, 25.0, 250.0, 150.0, WrapType.NONE);
// Use the "StrokeColor" property to set the color of the outline of the shape.
shape.setStrokeColor(Color.BLACK);
// Use the "FillColor" property to set the color of the inside area of the shape.
shape.setFillColor(Color.BLUE);
// The "Opacity" property determines how transparent the color is on a 0-1 scale,
// with 1 being fully opaque, and 0 being invisible.
// The shape fill by default is fully opaque, so we cannot see the text that this shape is on top of.
Assert.assertEquals(1.0d, shape.getFill().getOpacity());
// Set the shape fill color's opacity to a lower value so that we can see the text underneath it.
shape.getFill().setOpacity(0.3);
doc.save(getArtifactsDir() + "Shape.Fill.docx");
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
Color value.public void setStrokeColor(java.awt.Color value)
Remarks:
This is a shortcut to the Stroke.getColor() / Stroke.setColor(java.awt.Color) property.
The default value is java.awt.Color#getBlack().
Examples:
Shows how to fill a shape with a solid color.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Write some text, and then cover it with a floating shape.
builder.getFont().setSize(32.0);
builder.writeln("Hello world!");
Shape shape = builder.insertShape(ShapeType.CLOUD_CALLOUT, RelativeHorizontalPosition.LEFT_MARGIN, 25.0,
RelativeVerticalPosition.TOP_MARGIN, 25.0, 250.0, 150.0, WrapType.NONE);
// Use the "StrokeColor" property to set the color of the outline of the shape.
shape.setStrokeColor(Color.BLACK);
// Use the "FillColor" property to set the color of the inside area of the shape.
shape.setFillColor(Color.BLUE);
// The "Opacity" property determines how transparent the color is on a 0-1 scale,
// with 1 being fully opaque, and 0 being invisible.
// The shape fill by default is fully opaque, so we cannot see the text that this shape is on top of.
Assert.assertEquals(1.0d, shape.getFill().getOpacity());
// Set the shape fill color's opacity to a lower value so that we can see the text underneath it.
shape.getFill().setOpacity(0.3);
doc.save(getArtifactsDir() + "Shape.Fill.docx");
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
value - The corresponding Color value.public boolean getFilled()
Remarks:
This is a shortcut to the Fill.getVisible() / Fill.setVisible(boolean) property.
The default value is true.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
boolean value.public void setFilled(boolean value)
Remarks:
This is a shortcut to the Fill.getVisible() / Fill.setVisible(boolean) property.
The default value is true.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
value - The corresponding boolean value.public java.awt.Color getFillColor()
Remarks:
This is a shortcut to the Fill.getColor() / Fill.setColor(java.awt.Color) property.
The default value is java.awt.Color#getWhite().
Examples:
Shows how to fill a shape with a solid color.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Write some text, and then cover it with a floating shape.
builder.getFont().setSize(32.0);
builder.writeln("Hello world!");
Shape shape = builder.insertShape(ShapeType.CLOUD_CALLOUT, RelativeHorizontalPosition.LEFT_MARGIN, 25.0,
RelativeVerticalPosition.TOP_MARGIN, 25.0, 250.0, 150.0, WrapType.NONE);
// Use the "StrokeColor" property to set the color of the outline of the shape.
shape.setStrokeColor(Color.BLACK);
// Use the "FillColor" property to set the color of the inside area of the shape.
shape.setFillColor(Color.BLUE);
// The "Opacity" property determines how transparent the color is on a 0-1 scale,
// with 1 being fully opaque, and 0 being invisible.
// The shape fill by default is fully opaque, so we cannot see the text that this shape is on top of.
Assert.assertEquals(1.0d, shape.getFill().getOpacity());
// Set the shape fill color's opacity to a lower value so that we can see the text underneath it.
shape.getFill().setOpacity(0.3);
doc.save(getArtifactsDir() + "Shape.Fill.docx");
Color value.public void setFillColor(java.awt.Color value)
Remarks:
This is a shortcut to the Fill.getColor() / Fill.setColor(java.awt.Color) property.
The default value is java.awt.Color#getWhite().
Examples:
Shows how to fill a shape with a solid color.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Write some text, and then cover it with a floating shape.
builder.getFont().setSize(32.0);
builder.writeln("Hello world!");
Shape shape = builder.insertShape(ShapeType.CLOUD_CALLOUT, RelativeHorizontalPosition.LEFT_MARGIN, 25.0,
RelativeVerticalPosition.TOP_MARGIN, 25.0, 250.0, 150.0, WrapType.NONE);
// Use the "StrokeColor" property to set the color of the outline of the shape.
shape.setStrokeColor(Color.BLACK);
// Use the "FillColor" property to set the color of the inside area of the shape.
shape.setFillColor(Color.BLUE);
// The "Opacity" property determines how transparent the color is on a 0-1 scale,
// with 1 being fully opaque, and 0 being invisible.
// The shape fill by default is fully opaque, so we cannot see the text that this shape is on top of.
Assert.assertEquals(1.0d, shape.getFill().getOpacity());
// Set the shape fill color's opacity to a lower value so that we can see the text underneath it.
shape.getFill().setOpacity(0.3);
doc.save(getArtifactsDir() + "Shape.Fill.docx");
value - The corresponding Color value.public boolean hasImage()
throws java.lang.Exception
true if the shape has image bytes or links an image.
Examples:
Shows how to delete all shapes with images from a document.
Document doc = new Document(getMyDir() + "Images.docx");
ArrayList<Shape> shapes = (ArrayList<Shape>) IterableUtils.toList(doc.getChildNodes(NodeType.SHAPE, true));
Assert.assertEquals(9, IterableUtils.countMatches(shapes, s -> {
try {
return s.hasImage();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}));
for (Shape shape : shapes)
if (shape.hasImage())
shape.remove();
shapes = (ArrayList<Shape>) IterableUtils.toList(doc.getChildNodes(NodeType.SHAPE, true));
Assert.assertEquals(0, IterableUtils.countMatches(shapes, s -> {
try {
return s.hasImage();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}));
Shows how to extract images from a document, and save them to the local file system as individual files.
Document doc = new Document(getMyDir() + "Images.docx");
// Get the collection of shapes from the document,
// and save the image data of every shape with an image as a file to the local file system.
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
int imageIndex = 0;
for (Shape shape : (Iterable<Shape>) shapes) {
if (shape.hasImage()) {
// The image data of shapes may contain images of many possible image formats.
// We can determine a file extension for each image automatically, based on its format.
String imageFileName = MessageFormat.format("File.ExtractImages.{0}{1}", imageIndex, FileFormatUtil.imageTypeToExtension(shape.getImageData().getImageType()));
shape.getImageData().save(getArtifactsDir() + imageFileName);
imageIndex++;
}
}
true if the shape has image bytes or links an image.java.lang.Exceptionpublic ImageData getImageData()
null if the shape cannot have an image.
Examples:
Shows how to extract images from a document, and save them to the local file system as individual files.
Document doc = new Document(getMyDir() + "Images.docx");
// Get the collection of shapes from the document,
// and save the image data of every shape with an image as a file to the local file system.
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
int imageIndex = 0;
for (Shape shape : (Iterable<Shape>) shapes) {
if (shape.hasImage()) {
// The image data of shapes may contain images of many possible image formats.
// We can determine a file extension for each image automatically, based on its format.
String imageFileName = MessageFormat.format("File.ExtractImages.{0}{1}", imageIndex, FileFormatUtil.imageTypeToExtension(shape.getImageData().getImageType()));
shape.getImageData().save(getArtifactsDir() + imageFileName);
imageIndex++;
}
}
Shows how to insert a linked image into a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
String imageFileName = getImageDir() + "Windows MetaFile.wmf";
// Below are two ways of applying an image to a shape so that it can display it.
// 1 - Set the shape to contain the image.
Shape shape = new Shape(builder.getDocument(), ShapeType.IMAGE);
shape.setWrapType(WrapType.INLINE);
shape.getImageData().setImage(imageFileName);
builder.insertNode(shape);
doc.save(getArtifactsDir() + "Image.CreateLinkedImage.Embedded.docx");
// Every image that we store in shape will increase the size of our document.
Assert.assertTrue(new File(getArtifactsDir() + "Image.CreateLinkedImage.Embedded.docx").length() > 70000);
doc.getFirstSection().getBody().getFirstParagraph().removeAllChildren();
// 2 - Set the shape to link to an image file in the local file system.
shape = new Shape(builder.getDocument(), ShapeType.IMAGE);
shape.setWrapType(WrapType.INLINE);
shape.getImageData().setSourceFullName(imageFileName);
builder.insertNode(shape);
doc.save(getArtifactsDir() + "Image.CreateLinkedImage.Linked.docx");
// Linking to images will save space and result in a smaller document.
// However, the document can only display the image correctly while
// the image file is present at the location that the shape's "SourceFullName" property points to.
Assert.assertTrue(new File(getArtifactsDir() + "Image.CreateLinkedImage.Linked.docx").length() < 10000);
ImageData value.public OleFormat getOleFormat()
null.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
OleFormat value.public TextBox getTextBox()
Examples:
Shows how to set the orientation of text inside a text box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
TextBox textBox = textBoxShape.getTextBox();
// Move the document builder to inside the TextBox and add text.
builder.moveTo(textBoxShape.getLastParagraph());
builder.writeln("Hello world!");
builder.write("Hello again!");
// Set the "LayoutFlow" property to set an orientation for the text contents of this text box.
textBox.setLayoutFlow(layoutFlow);
doc.save(getArtifactsDir() + "Shape.TextBoxLayoutFlow.docx");
TextBox value.public TextPath getTextPath()
Examples:
Shows how to work with WordArt.
public void insertTextPaths() throws Exception {
Document doc = new Document();
// Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word.
// Provide a "ShapeType" as an argument to set a shape for the WordArt.
Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.",
"Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT);
// Apply the "Bold" and "Italic" formatting settings to the text using the respective properties.
shape.getTextPath().setBold(true);
shape.getTextPath().setItalic(true);
// Below are various other text formatting-related properties.
Assert.assertFalse(shape.getTextPath().getUnderline());
Assert.assertFalse(shape.getTextPath().getShadow());
Assert.assertFalse(shape.getTextPath().getStrikeThrough());
Assert.assertFalse(shape.getTextPath().getReverseRows());
Assert.assertFalse(shape.getTextPath().getXScale());
Assert.assertFalse(shape.getTextPath().getTrim());
Assert.assertFalse(shape.getTextPath().getSmallCaps());
Assert.assertEquals(36.0, shape.getTextPath().getSize());
Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText());
Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType());
// Use the "On" property to show/hide the text.
shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT);
shape.getTextPath().setOn(true);
shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT);
shape.getTextPath().setOn(false);
// Use the "Kerning" property to enable/disable kerning spacing between certain characters.
shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT);
shape.getTextPath().setKerning(true);
shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT);
shape.getTextPath().setKerning(false);
// Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default).
shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN);
shape.getTextPath().setSpacing(0.1);
// Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise.
shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE);
shape.getTextPath().setRotateLetters(true);
// Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height.
shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP);
shape.getTextPath().setSameLetterHeights(true);
// By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting.
shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT);
Assert.assertTrue(shape.getTextPath().getFitShape());
shape.getTextPath().setSize(24.0);
// If we set the "FitShape: property to "false", the text will keep the size
// which the "Size" property specifies regardless of the size of the shape.
// Use the "TextPathAlignment" property also to align the text to a side of the shape.
shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT);
shape.getTextPath().setFitShape(false);
shape.getTextPath().setSize(24.0);
shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT);
doc.save(getArtifactsDir() + "Shape.InsertTextPaths.docx");
}
/// <summary>
/// Insert a new paragraph with a WordArt shape inside it.
/// </summary>
private static Shape appendWordArt(Document doc, String text, String textFontFamily, double shapeWidth, double shapeHeight, Color wordArtFill, Color line, int wordArtShapeType) throws Exception {
// Create an inline Shape, which will serve as a container for our WordArt.
// The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it.
// These types will have "WordArt object" in the description,
// and their enumerator constant names will all start with "Text".
Shape shape = new Shape(doc, wordArtShapeType);
{
shape.setWrapType(WrapType.INLINE);
shape.setWidth(shapeWidth);
shape.setHeight(shapeHeight);
shape.setFillColor(wordArtFill);
shape.setStrokeColor(line);
}
shape.getTextPath().setText(text);
shape.getTextPath().setFontFamily(textFontFamily);
Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc));
para.appendChild(shape);
return shape;
}
TextPath value.public Paragraph getFirstParagraph()
Examples:
Shows how to create and format a text box.
Document doc = new Document();
// Create a floating text box.
Shape textBox = new Shape(doc, ShapeType.TEXT_BOX);
textBox.setWrapType(WrapType.NONE);
textBox.setHeight(50.0);
textBox.setWidth(200.0);
// Set the horizontal, and vertical alignment of the text inside the shape.
textBox.setHorizontalAlignment(HorizontalAlignment.CENTER);
textBox.setVerticalAlignment(VerticalAlignment.TOP);
// Add a paragraph to the text box and add a run of text that the text box will display.
textBox.appendChild(new Paragraph(doc));
Paragraph para = textBox.getFirstParagraph();
para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
Run run = new Run(doc);
run.setText("Hello world!");
para.appendChild(run);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(textBox);
doc.save(getArtifactsDir() + "Shape.CreateTextBox.docx");
public Paragraph getLastParagraph()
Examples:
Shows how to set the orientation of text inside a text box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
TextBox textBox = textBoxShape.getTextBox();
// Move the document builder to inside the TextBox and add text.
builder.moveTo(textBoxShape.getLastParagraph());
builder.writeln("Hello world!");
builder.write("Hello again!");
// Set the "LayoutFlow" property to set an orientation for the text contents of this text box.
textBox.setLayoutFlow(layoutFlow);
doc.save(getArtifactsDir() + "Shape.TextBoxLayoutFlow.docx");
public HorizontalRuleFormat getHorizontalRuleFormat()
null.
Examples:
Shows how to insert a horizontal rule shape, and customize its formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertHorizontalRule();
HorizontalRuleFormat horizontalRuleFormat = shape.getHorizontalRuleFormat();
horizontalRuleFormat.setAlignment(HorizontalRuleAlignment.CENTER);
horizontalRuleFormat.setWidthPercent(70.0);
horizontalRuleFormat.setHeight(3.0);
horizontalRuleFormat.setColor(Color.BLUE);
horizontalRuleFormat.setNoShade(true);
Assert.assertTrue(shape.isHorizontalRule());
Assert.assertTrue(shape.getHorizontalRuleFormat().getNoShade());
HorizontalRuleFormat value.public AdjustmentCollection getAdjustments()
Examples:
Shows how to work with adjustment raw values.
Document doc = new Document(getMyDir() + "Rounded rectangle shape.docx");
Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
AdjustmentCollection adjustments = shape.getAdjustments();
Assert.assertEquals(1, adjustments.getCount());
Adjustment adjustment = adjustments.get(0);
Assert.assertEquals("adj", adjustment.getName());
Assert.assertEquals(16667, adjustment.getValue());
adjustment.setValue(30000);
doc.save(getArtifactsDir() + "Shape.Adjustments.docx");
AdjustmentCollection value.public SignatureLine getSignatureLine()
SignatureLine object if the shape is a signature line. Returns null otherwise.
Remarks:
You can insert new SignatureLine into the document using DocumentBuilder.insertSignatureLine(com.aspose.words.SignatureLineOptions) and
Examples:
Shows how to create a line for a signature and insert it into a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions options = new SignatureLineOptions();
{
options.setAllowComments(true);
options.setDefaultInstructions(true);
options.setEmail("john.doe@management.com");
options.setInstructions("Please sign here");
options.setShowDate(true);
options.setSigner("John Doe");
options.setSignerTitle("Senior Manager");
}
// Insert a shape that will contain a signature line, whose appearance we will
// customize using the "SignatureLineOptions" object we have created above.
// If we insert a shape whose coordinates originate at the bottom right hand corner of the page,
// we will need to supply negative x and y coordinates to bring the shape into view.
Shape shape = builder.insertSignatureLine(options, RelativeHorizontalPosition.RIGHT_MARGIN, -170.0,
RelativeVerticalPosition.BOTTOM_MARGIN, -60.0, WrapType.NONE);
Assert.assertTrue(shape.isSignatureLine());
// Verify the properties of our signature line via its Shape object.
SignatureLine signatureLine = shape.getSignatureLine();
Assert.assertEquals(signatureLine.getEmail(), "john.doe@management.com");
Assert.assertEquals(signatureLine.getSigner(), "John Doe");
Assert.assertEquals(signatureLine.getSignerTitle(), "Senior Manager");
Assert.assertEquals(signatureLine.getInstructions(), "Please sign here");
Assert.assertTrue(signatureLine.getShowDate());
Assert.assertTrue(signatureLine.getAllowComments());
Assert.assertTrue(signatureLine.getDefaultInstructions());
doc.save(getArtifactsDir() + "Shape.SignatureLine.docx");
M:Aspose.Words.DocumentBuilder.InsertSignatureLine(Aspose.Words.SignatureLineOptions,Aspose.Words.Drawing.RelativeHorizontalPosition,System.Double,Aspose.Words.Drawing.RelativeVerticalPosition,System.Double,Aspose.Words.Drawing.WrapType)SignatureLine object if the shape is a signature line.public int getTextBoxWrapMode_ITextBox()
public int getTextboxLayoutFlow_ITextBox()
public boolean hasVerticalTextFlow_ITextBox()
public byte getMarkupLanguage_ITextBox()
public boolean hasChart()
true if this Shape has a Chart.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
public boolean hasSmartArt()
true if this Shape has a SmartArt object.
Examples:
Shows how to count the number of shapes in a document with SmartArt objects.
Document doc = new Document(getMyDir() + "SmartArt.docx");
int count = 0;
for (Shape shape : (Iterable<Shape>) doc.getChildNodes(NodeType.SHAPE, true)) {
if (shape.hasSmartArt())
count++;
}
Assert.assertEquals(2, count);
true if this Shape has a SmartArt object.public void updateSmartArtDrawing()
throws java.lang.Exception
Remarks:
Microsoft Word generates and saves the pre-rendered drawing along with SmartArt object. However, if the document is saved by other applications, the pre-rendered SmartArt drawing may be missing or incorrect. If pre-rendered drawing is available then Aspose.Words uses it to render the SmartArt object. If pre-rendered drawing is missing then Aspose.Words uses its own SmartArt cold rendering engine to render the SmartArt object. If pre-rendered drawing is incorrect then it is required to call this method to invoke the SmartArt cold rendering engine.
java.lang.Exceptionpublic Chart getChart()
Chart.
Remarks:
This property will return the Chart object only if hasChart() property is true for this Shape, and will throw an exception otherwise.
Examples:
Shows how to iterate over all the shapes in a document.
public void visitShapes() throws Exception {
Document doc = new Document(getMyDir() + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Logs appearance-related information about visited shapes.
/// </summary>
private static class ShapeAppearancePrinter extends DocumentVisitor {
public ShapeAppearancePrinter() {
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// Appends a line to the StringBuilder with one prepended tab character for each indent level.
/// </summary>
private void appendLine(String text) {
for (int i = 0; i < mTextIndentLevel; i++) {
mStringBuilder.append('\t');
}
mStringBuilder.append(text + "\n");
}
/// <summary>
/// Return all the text that the StringBuilder has accumulated.
/// </summary>
public String getText() {
return MessageFormat.format("Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
/// <summary>
/// Called when this visitor visits the start of a Shape node.
/// </summary>
public int visitShapeStart(Shape shape) {
appendLine(MessageFormat.format("Shape found: {0}", shape.getShapeType()));
mTextIndentLevel++;
if (shape.hasChart())
appendLine(MessageFormat.format("Has chart: {0}", shape.getChart().getTitle().getText()));
appendLine(MessageFormat.format("Extrusion enabled: {0}", shape.getExtrusionEnabled()));
appendLine(MessageFormat.format("Shadow enabled: {0}", shape.getShadowEnabled()));
appendLine(MessageFormat.format("StoryType: {0}", shape.getStoryType()));
if (shape.getStroked()) {
Assert.assertEquals(shape.getStrokeColor(), shape.getStroke().getColor());
appendLine(MessageFormat.format("Stroke colors: {0}, {1}", shape.getStroke().getColor(), shape.getStroke().getColor2()));
appendLine(MessageFormat.format("Stroke weight: {0}", shape.getStrokeWeight()));
}
if (shape.getFilled())
appendLine(MessageFormat.format("Filled: {0}", shape.getFillColor()));
if (shape.getOleFormat() != null)
appendLine(MessageFormat.format("Ole found of type: {0}", shape.getOleFormat().getProgId()));
if (shape.getSignatureLine() != null)
appendLine(MessageFormat.format("Found signature line for: {0}, {1}", shape.getSignatureLine().getSigner(), shape.getSignatureLine().getSignerTitle()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a Shape node.
/// </summary>
public int visitShapeEnd(Shape shape) {
mTextIndentLevel--;
mShapesVisited++;
appendLine(MessageFormat.format("End of {0}", shape.getShapeType()));
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the start of a GroupShape node.
/// </summary>
public int visitGroupShapeStart(GroupShape groupShape) {
appendLine(MessageFormat.format("Shape group found: {0}", groupShape.getShapeType()));
mTextIndentLevel++;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when this visitor visits the end of a GroupShape node.
/// </summary>
public int visitGroupShapeEnd(GroupShape groupShape) {
mTextIndentLevel--;
appendLine(MessageFormat.format("End of {0}", groupShape.getShapeType()));
return VisitorAction.CONTINUE;
}
private int mShapesVisited;
private int mTextIndentLevel;
private final StringBuilder mStringBuilder;
}
Chart value.