You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Nicolas Torneri <ni...@gmail.com> on 2012/07/17 18:04:36 UTC

XSLFConnectorShape creates a link between to random shapes

Hello,

I am using POI-XSLF to create .pptx documents. How can I create a connector
shape so that it is linked to two other shapes ?

For example:

  // create new slideshow
  XMLSlideShow ppt = new XMLSlideShow();
  // create new slide
  XSLFSlide slide = ppt.createSlide();

  // create a first random shape
  XSLFAutoShape shape1 = slide.createAutoShape();
  shape1.setShapeType(XSLFShapeType.RECT);
  shape1.setAnchor(new Rectangle(100, 100, 200, 300));
  shape1.setLineColor(new Color(0));
  shape1.setLineWidth(1.0f);

  // create a second random shape
  XSLFAutoShape shape2 = slide.createAutoShape();
  shape2.setShapeType(XSLFShapeType.RECT);
  shape2.setAnchor(new Rectangle(400, 100, 300, 200));
  shape2.setLineColor(new Color(0));
  shape2.setLineWidth(1.0f);

  // create a connector shape
  XSLFConnectorShape connector = slide1.createConnector();
  connector.setShapeType(XSLFShapeType.LINE);

Here, I would like connector to be bound to shape1 and shape2. How can I
achieve that ?

Thanks in advance !
Nicolas

Re: XSLFConnectorShape creates a link between to random shapes

Posted by Jithesh Chandra <ji...@gmail.com>.
Hi ,

I am also trying to work on connector shapes and its become more of a dead
block can you forward me that attachment .



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/XSLFConnectorShape-creates-a-link-between-to-random-shapes-tp5710474p5715263.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: XSLFConnectorShape creates a link between to random shapes

Posted by Yegor Kozlov <ye...@dinom.ru>.
You can figure out how to set connectors from reverse engineering:
create a pptx file with two shapes and a connector. Unzip the file and
have a look at slide.xml. The connector shape has two properties which
tell PowerPoint what and how to connect.

Below if the fragment that sets this information, notice a:stCxn
(connection start) and a:endCxn (connection end).
The id attribute specifies the id of the shape to make the connection to.
The idx attribute is the side to attach the connector. For rectangle
it can be one of left=1, bottom=2, right=3 or top=4.

<p:cxnSp>
<p:nvCxnSpPr>
<p:cNvPr id="6" name="Elbow Connector 5"/>
<p:cNvCxnSpPr>
<a:stCxn id="2" idx="3"/>
<a:endCxn id="3" idx="1"/>
</p:cNvCxnSpPr>
<p:nvPr/>
</p:nvCxnSpPr>


The code below creates a slide with two rectangles connected by a bent
connector.

        XMLSlideShow pptx = new XMLSlideShow();
        XSLFSlide slide = pptx.createSlide();

        XSLFAutoShape rect1 = slide.createAutoShape();
        rect1.setShapeType(XSLFShapeType.RECT);
        rect1.setAnchor(new Rectangle(100, 100, 100, 100));
        rect1.setFillColor(Color.blue);

        XSLFAutoShape rect2 = slide.createAutoShape();
        rect2.setShapeType(XSLFShapeType.RECT);
        rect2.setAnchor(new Rectangle(300, 300, 100, 100));
        rect2.setFillColor(Color.red);


        XSLFConnectorShape connector1 = slide.createConnector();
        connector1.setAnchor(new Rectangle(200, 150, 100, 200));

        CTConnector ctConnector = (CTConnector)connector1.getXmlObject();
        ctConnector.getSpPr().getPrstGeom().setPrst(STShapeType.BENT_CONNECTOR_3);
        CTNonVisualConnectorProperties cx =
ctConnector.getNvCxnSpPr().getCNvCxnSpPr();
        // connection start
        CTConnection stCxn = cx.addNewStCxn();
        stCxn.setId(rect1.getShapeId());
        // side of the rectangle to attach the connector: left=1,
bottom=2,right=3, top=4
        stCxn.setIdx(2);

        CTConnection end = cx.addNewEndCxn();
        end.setId(rect2.getShapeId());
        // side of the rectangle to attach the connector: left=1,
bottom=2,right=3, top=4
        end.setIdx(3);

        FileOutputStream out = new FileOutputStream("xslf-connector.pptx");
        pptx.write(out);
        out.close();


Hope it  helps.

Yegor

On Tue, Sep 11, 2012 at 2:06 AM, LarryN <cr...@gmail.com> wrote:
> Hello All,
>
> Has anyone made any progress on this?
>
> My project team are using XSLF, but the inability to connect shapes is an
> unexpected brick wall for us.
>
> We will have lost a lot of time if we can not move forward.
>
> Any suggestions would be invaluable at the point.
>
>
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/XSLFConnectorShape-creates-a-link-between-to-random-shapes-tp5710474p5710902.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: XSLFConnectorShape creates a link between to random shapes

Posted by LarryN <cr...@gmail.com>.
Hello All,

Has anyone made any progress on this?

My project team are using XSLF, but the inability to connect shapes is an
unexpected brick wall for us.

We will have lost a lot of time if we can not move forward.

Any suggestions would be invaluable at the point.



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/XSLFConnectorShape-creates-a-link-between-to-random-shapes-tp5710474p5710902.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: XSLFConnectorShape creates a link between to random shapes

Posted by Nicolas <ni...@gmail.com>.
I expected to find some methods on the XSLFConnectorShape object to bind shapes
together, like:

XSLFConnectorShape connector = slide1.createConnector();
connector.setSource(shape1);
connector.setDestination(shape2);

... but I understand some research needs to be done to come to this point.

I'll try to dig into the subject and surely will post my findings here.
Thank you very much for your reply and for pointing me to the right direction.

Nicolas



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: XSLFConnectorShape creates a link between to random shapes

Posted by Yegor Kozlov <ye...@dinom.ru>.
Connectors between shapes are not yet supported. They *should* be
instances or sub-classes of XSLFConnectorShape but I didn't yet
research what properties need to be set to make them work.

My advise is to create a simple .pptx file with two shapes and a
connector between them. Unzip the file, open slide.xml and see the
structure. Compare it with a similar file created by POI, you want to
look at CTConnector objects.

Then grab low-level xml bean in your java code:

XmlObject xml = connector .getXmlObject();

and modify it to match the reference .pptx created in PowerPoint.

Hope it helps.

Once you find how to set connectors, please share your knoledge on the
mailing list or even better submit a patch.

Yegor

On Tue, Jul 17, 2012 at 8:04 PM, Nicolas Torneri
<ni...@gmail.com> wrote:
> Hello,
>
> I am using POI-XSLF to create .pptx documents. How can I create a connector
> shape so that it is linked to two other shapes ?
>
> For example:
>
>   // create new slideshow
>   XMLSlideShow ppt = new XMLSlideShow();
>   // create new slide
>   XSLFSlide slide = ppt.createSlide();
>
>   // create a first random shape
>   XSLFAutoShape shape1 = slide.createAutoShape();
>   shape1.setShapeType(XSLFShapeType.RECT);
>   shape1.setAnchor(new Rectangle(100, 100, 200, 300));
>   shape1.setLineColor(new Color(0));
>   shape1.setLineWidth(1.0f);
>
>   // create a second random shape
>   XSLFAutoShape shape2 = slide.createAutoShape();
>   shape2.setShapeType(XSLFShapeType.RECT);
>   shape2.setAnchor(new Rectangle(400, 100, 300, 200));
>   shape2.setLineColor(new Color(0));
>   shape2.setLineWidth(1.0f);
>
>   // create a connector shape
>   XSLFConnectorShape connector = slide1.createConnector();
>   connector.setShapeType(XSLFShapeType.LINE);
>
> Here, I would like connector to be bound to shape1 and shape2. How can I
> achieve that ?
>
> Thanks in advance !
> Nicolas

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org