Hi, I am drawing my presentation file based on AutoShapes, basically rectangles, ellipses and connectors. Then when I move them in PPT the connectors follow the Shapes. After running the following code. I don't see the Connector. Once I move the shape around then the connector appear. What am I doing wrong ? I have no Idea. I tried the same code using Aspose.Slides and the connectors are drawn properly.
I opened the pptx in Microsoft Office Professional Plus 2013 (running windows) and tried 2011 running on Mac. Both have the same behaviour.
ExportingRealPathway-3fca0f08f59b8b00.pptx
Description: MS-Powerpoint 2007 presentation
This is my class
public class ExportingRealPathway {
public static void main(String[] args) {
XMLSlideShow pptx = new XMLSlideShow();
XSLFSlide slide = pptx.createSlide();
GraphicsDevice gd =
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();
Dimension pageSize = new Dimension(width-600, height-400);
pptx.setPageSize(pageSize);
// for of nodes parsing and adding auto shapes
XSLFAutoShape r1 = slide.createAutoShape();
r1.setShapeType(ShapeType.RECT);
r1.setAnchor(new Rectangle2D.Double(20, 20, 100, 50));
r1.setLineColor(Color.blue);
r1.setFillColor(Color.lightGray);
XSLFAutoShape c1 = slide.createAutoShape();
c1.setShapeType(ShapeType.ELLIPSE);
c1.setAnchor(new Rectangle2D.Double(60, 200, 87, 50));
c1.setLineColor(Color.GREEN);
c1.setFillColor(new Color(100, 100, 100));
XSLFAutoShape c2 = slide.createAutoShape();
c2.setShapeType(ShapeType.ELLIPSE);
c2.setAnchor(new Rectangle2D.Double(c1.getAnchor().getX()+70, 400, 87,
50));
c2.setLineColor(Color.GREEN);
c2.setFillColor(new Color(100, 100, 100));
XSLFAutoShape c3 = slide.createAutoShape();
c3.setShapeType(ShapeType.ELLIPSE);
c3.setAnchor(new Rectangle2D.Double(700, 400, 87, 50));
c3.setLineColor(Color.GREEN);
c3.setFillColor(new Color(100, 100, 100));
XSLFAutoShape reactionLeftConnection = slide.createAutoShape();
reactionLeftConnection.setShapeType(ShapeType.ELLIPSE);
reactionLeftConnection.setAnchor(new Rectangle2D.Double(200, 200, 1,
1));
reactionLeftConnection.setLineColor(Color.white);
reactionLeftConnection.setFillColor(Color.white);
XSLFAutoShape reaction = slide.createAutoShape();
reaction.setShapeType(ShapeType.RECT);
reaction.setAnchor(new Rectangle2D.Double(400, 200, 23, 19));
reaction.setLineColor(Color.black);
XSLFAutoShape reactionRightConnection = slide.createAutoShape();
reactionRightConnection.setShapeType(ShapeType.ELLIPSE);
reactionRightConnection.setAnchor(new Rectangle2D.Double(600, 200, 1,
1));
reactionRightConnection.setLineColor(Color.white);
reactionRightConnection.setFillColor(Color.white);
XSLFAutoShape catalyst = slide.createAutoShape();
catalyst.setShapeType(ShapeType.ELLIPSE);
catalyst.setAnchor(new
Rectangle2D.Double(reaction.getAnchor().getMinX() +
reaction.getAnchor().getWidth() / 2, reaction.getAnchor().getMinY()-10, 10,
10));
catalyst.setLineColor(Color.black);
catalyst.setFillColor(Color.white);
XSLFAutoShape r2 = slide.createAutoShape();
r2.setShapeType(ShapeType.RECT);
r2.setAnchor(new Rectangle2D.Double(800, 200, 100, 50));
r2.setLineColor(Color.BLUE);
r2.setFillColor(Color.yellow);
connect(slide, r1, catalyst, STShapeType.STRAIGHT_CONNECTOR_1);
connect(slide, c1, reactionLeftConnection,
STShapeType.STRAIGHT_CONNECTOR_1);
connect(slide, c2, reactionLeftConnection,
STShapeType.STRAIGHT_CONNECTOR_1);
connect(slide, reaction, reactionLeftConnection,
STShapeType.STRAIGHT_CONNECTOR_1);
connect(slide, reaction, reactionRightConnection,
STShapeType.STRAIGHT_CONNECTOR_1);
connect(slide, r2, reactionRightConnection,
STShapeType.STRAIGHT_CONNECTOR_1);
connect(slide, c3, reactionRightConnection,
STShapeType.STRAIGHT_CONNECTOR_1);
FileOutputStream out;
try {
out = new FileOutputStream("ExportRealPathway.pptx");
pptx.write(out);
out.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void connect(XSLFSlide slide, XSLFShape start, XSLFShape end,
STShapeType.Enum type){
XSLFConnectorShape connector = slide.createConnector();
connector.setAnchor(new Rectangle2D.Double(1, 1, 1, 1));
connector.setLineColor(Color.black);
connector.setShapeType(ShapeType.LINE);
CTConnector ctConnector = (CTConnector)connector.getXmlObject();
ctConnector.getSpPr().getPrstGeom().setPrst(type);
CTNonVisualConnectorProperties cx =
ctConnector.getNvCxnSpPr().getCNvCxnSpPr();
// connection start
CTConnection stCxn = cx.addNewStCxn();
stCxn.setId(start.getShapeId());
// side of the rectangle to attach the connector: left=1,
bottom=2,right=3, top=4
stCxn.setIdx(3); // set 3 just for testing ...
CTConnection endCxn = cx.addNewEndCxn();
endCxn.setId(end.getShapeId());
// side of the rectangle to attach the connector: left=1,
bottom=2,right=3, top=4
endCxn.setIdx(3); // set 3 just for testing ...
}
}
I am running on IntelliJ IDEA 2016 1.3 Java 8 on Mac OS X 10.10 Yosemite.
These are the dependencies I am using
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.15-beta2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15-beta2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.3</version>
</dependency>
I am not building any code directly from SVN on any nightly build. Although, I
built 3.16-beta2 for testing purpose it behaved the same I kept the one form
MVNRepository
Thank you
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
